MD Pabel
Back to Notes

Docker

MD Pabel

MD Pabel / May 11, 2024

6 min read

Table of contents

Images

Base Image:

Loading code...

commands:

Loading code...

Copying application files & directories

Loading code...

Excluding files & directories

Loading code...

Running commands

Loading code...

Setting environment variables

Loading code...

inspect env variable:

Loading code...

Exposing PORTs

EXPOSE command desn't automatically publish the port on the host.

Loading code...

Managing users in linux

Loading code...

Setting the users

When you use USER app in a Dockerfile, it only sets the user for subsequent RUN, CMD, and ENTRYPOINT commands, not for COPY commands. The COPY command operates at the filesystem level within the Docker image and does not inherit the user set by USER.

Loading code...
Loading code...

Entrypoints

Loading code...

Speeding up builds

An image is a collections of layers that only includes modified files. Once a layer is rebuilt, all the following layers have to be rebuilt. Put instructions that change a lot at the bottom, and instructions that don't change much at the top.

Loading code...

Removing images and containers

Loading code...

Tagging images

Loading code...

Sharing Images

Loading code...

Saving & Loading an Image

Loading code...

Containers

Starting containers

Loading code...

Viewing logs

Loading code...

Publishing ports

Loading code...

Execturing commands in running containers

Execute commands within a running container using the exec command.

Loading code...

Stopping and starting containers

Create a new container using the docker run command, and restart a stopped container using docker start.

Loading code...

Removing containers

Loading code...

Volumes

Loading code...
Loading code...

Copying files b/w host and containers

Loading code...

Sharing the source code with a container

Publishing changes

  • For production: build a new image
  • For development: we don't want to build a new image every time.
Loading code...

Remove images and containers

Loading code...

Running multi container applications

Yaml

Loading code...
Loading code...

docker-compose.yml

Loading code...

Building images

Loading code...

Starting & Stopping the application

Loading code...

Viewing logs

Loading code...

Publishing changes

Loading code...

validate and display the configuration

Loading code...

Use Compose Watch

Loading code...
Loading code...