sensharma
3/25/2018 - 4:46 AM

docker commands

docker commands

General Nuggets:

DockerFile:

  • use COPY, not ADD, for including tar files from local drive into docker build. ADD implicitly untars it with funny consequences
  • USER has the effect of running all subsequent RUN, CMD & ENTRYPOINT instructions as that user. For copying moving files around in a particular image, best done before setting user, else it may say "access denied"

Managing images

CommandDescription
docker tag <old_name> <new_name>
followed by
docker rmi <old_name>
Rename an image: Essentially 2 steps, first tag a different image with the old name:tag & then remove the image with the old name (the older one is now tagless)
docker rmi <IMAGE ID>Remove/delete an image
docker save <repo/image:tag> -o <filename.tar.gz>Saving an image from local repo as a tar file
docker load < <filename.tar.gz> OR
docker load --input <filename.tar.gz>
Load an image into local repo from a tar file

Modifying images

CommandDescription
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]To run an image as a container, modify it and then save modified image
Make sure you don't run it with --rm, else the container will disappear and we can't commit after exiting
Commiting with modified CMD & EXPOSE instructions: https://docs.docker.com/engine/reference/commandline/commit/#commit-a-container-with-new-configurations

Managing containers

docker rm <container name> | removes the container

Listing

CommandDescription
docker psLists the running containers (instances)
docker ps -aLists all (running and stopped) containers (instances)
docker image lsLists all images in the local repo