Docker CS

Docker CS


Frequently used #

Build #

  1. Build: docker build -t tag-name # from dir that contains Dockerfile docker build . # from dir that contains Dockerfile “.”:

    • means Dockerfile is located in the current directory
    • copy current directory contents into image
  2. build with Naming Images: docker build -t image-name # from dir that contains Dockerfile

Containers #

  1. Create a container with name docker run --name container_name image_name

  2. Create container in detached mode docker run -d --name container_name image_name

  3. Create Container with env variables docker run --name bakery -p 8001:8000 -e DEVELOPMENT_MODE=True bakery-img

  4. Publish ports To creates a firewall rule which maps a container port to a port on the Docker host to the outside world docker run --name container_name -p host-port:container-port image_name

  5. list containers docker container ls --all | grep s3fs docker container ls -f s3fs ref

  6. container logs docker logs -f --until=2s container-name

  7. Remove container docker rm container-name

  8. SSH to container docker exec -it container-name bash-command

    e.g.

Docker registry #

  1. Login docker login # default registry is docker hub docker login registry-1.docker.io

  2. Push

    1. create a repository on docker hub and copy the command, docker push jaaved9/assessment:tagname docker push jaaved9/assessment:latest

    2. To push to private or non docker hub repo docker push localhost.localdomain:5000/ubuntu # give full URL

  3. tagging remote repo docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Inspect Details #

docker inspect hash
docker top hash

Mounting #

“-mount” or “-v” -v <source>:<target>

docker run -d --name nginx --network host \
      -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro \
     nginx:1.20


No notes link to this note

Previous Next