Basic Docker Commands

Build container instance

docker build

docker build -t ${IMAGE}:latest

Create a container instance

docker create $IMAGE

Create and start container instance

docker run $IMAGE

docker run $IMAGE $COMMAND

docker run -p ${FROM_PORT}:${TO_PORT} $IMAGE

Start container instance

docker start $CONTAINER_ID

docker start -a $CONTAINER_ID

List containers

docker ps

docker ps -a

Stop containers

docker stop $CONTAINER_ID

docker kill $CONTAINER_ID

Delete containers

docker system prune

Get container output

docker logs $CONTAINER_ID

Execute commands in container

docker exec -it $CONTAINER_ID $COMMAND

docker exec -it $CONTAINER_ID sh

Manually update container

docker commit -c $COMMAND $CONTAINER_ID

Dockerfile Components

FROM $BASE_IMAGE

WORKDIR

COPY/ADD

RUN

CMD

ENTRYPOINT

Docker Compose Syntax

Note that when two or more containers are created using Docker Compose, they automatically share the same network and can freely exchange information.

Docker-compose yaml

version

services

  • build:
    • /local/path/to/build
  • image:
    • /built/image/to/use
  • volumes:
    • /local/path:/container/path:flag
  • ports:
    • local:container
  • restart {no, always, on-failure, unless-stopped}

Launch docker-compose yaml file

docker-compose up

docker-compose up --build

docker-compose up -d

docker-compose down