Docker Images


Download image

docker pull [image-name]

List images

docker images

Create image out of Dockerfile

docker build -t [image-name] [folder-where-Dockerfile-present]

[image-name] is repository name and tag followed by colon, if hostname not specified, then it points to Dockerhub
examples

  1. ubuntu
    repository: ubuntu
    tag: latest
  2. ubuntu:v1
    repository: ubuntu
    tag: v1
  3. myregistryhost:5000/fedora/httpd:v1
    repository: myregistryhost:5000/fedora/httpd
    tag: v1

Tag an image

docker tag [source-image-name] [target-image-name]

Delete images: it deletes tag if multiple tags present

docker rmi [image-name]

Docker Containers


List running container

docker container list
docker ps

List all containers

docker container list -a
docker ps -a

Create a container out of docker image

docker create -ti --name [container-name] [image-name]

Start container

docker start -i [container-name]

Create and Start new container

  • It also pulls the image if is is not available locally
docker run -ti --name [container-name] [image-name]

More options

  • --rm: automatically remove the container when it exits
  • -p ${OUTSIDE_PORT}:${INTERNAL_PORT}:
    • example: -p 8888:80
    • forward docker’s internal 80 port to outside at 8888
  • -v ${OUTSIDE_FOLDER}:${MOUNT_PATH}: mount OUTSIDE_FOLDER to MOUNT_PATH inside docker

Stop container

docker stop [container-name]

Delete containers

docker rm [container-name]

Create image out of container

docker commit [container-name] [image-name]

Get Inside running container

docker exec -it [container-name] bash

Get logs of container

docker logs [container-name]
 
# tail the logs
docker logs -f [container-name]

Docker Publish Registry


Pushing Docker image to container registry

docker login
docker tag [image-name] {{ hostname/image-name:tag }}
docker push {{ hostname/image-name:tag }}