02. Docker Installation and commands

Parmeshwar C
3 min readJan 16, 2021
Docker Commands

Installation -

  1. Installation of docker can change or become more convenient on time being so I am not listing down installation steps here rather I am providing an official link for installation. Follow the steps there according to your system.
  2. Docker on Windows
  3. Docker on Mac
  4. Docker on Ubuntu Linux
  5. For Ubuntu Linux, if you are willing to install it with fewer efforts then follow this link. here you can install it using a script. there are other manual options also you can try if you are more interested in it.

Frequently used commands:-

docker build

  1. To create an image from Dockerfile
  2. We have already gone through this command while creating an image through Dockerfile in 01.Docker Basics
  3. You can explore more option used for this command in this document

4. Ex — docker build -f Dockerfile -t MyWebApp:1.0 .

docker pull -

  1. To pull images from the docker hub.
  2. Ex- docker pull ubuntu: latest
  3. Where “latest” is the tag of that image. There can be many tags like ubuntu:16, ubuntu: bionic, etc.

docker run -

  1. To run the image. It first checks in the local space if that image is available or it will try to pull from docker-hub.
  2. Ex: docker run ubuntu: latest

docker ps -

  1. To checklist of containers
  2. “-a” option shows all containers some are running or some might be exited.
  3. Ex: docker ps -a

docker images -

  1. shows a list of images currently available locally
  2. ex: Dockers images

docker rm <container id>

1. for deleting container, you have to pass container id

docker rmi <image id> to delete image

Container Starting and stopping:-

  1. docker start — starts a container so it is running.
  2. docker stop — stops a running container.
  3. docker restart — stops and starts a container.
  4. docker pause — pauses a running container, “freezing” it in place.
  5. docker unpause — will unpause a running container.
  6. docker wait — blocks until running container stops.
  7. docker kill — sends a SIGKILL to a running container.
  8. docker attach — will connect to a running container.

container Information:-

  1. docker ps — shows running containers.
  2. docker logs — gets logs from the container.
  3. docker inspect — looks at all the info on a container (including IP address).
  4. docker events — gets events from containers.
  5. docker port — shows a public-facing port of the container.
  6. docker top — shows running processes in the container.
  7. docker stats — shows containers’ resource usage statistics.
  8. docker diff — shows changed files in the container’s FS.

Container import/ export :-

  1. docker cp — copies files or folders between a container and the local filesystem.
  2. docker export — turns container filesystem into tarball archive stream to STDOUT.

Container execution

  1. docker exec — to execute a command in a container.

Commands related to images

  1. docker images — shows all images.
  2. docker import — creates an image from a tarball.
  3. docker build — creates an image from Dockerfile.
  4. docker commit — creates an image from a container, pausing it temporarily if it is running.
  5. docker rmi — removes an image.
  6. docker load — loads an image from a tar archive as STDIN, including images and tags.
  7. docker save — saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions.
  8. docker history — shows the history of the image.
  9. docker tag — tags an image to a name (local or registry).

These are commands which we will be using till we reach an advanced stage. We will get some information about how to make a docker file if there are, multiple modules in the project like server and database.

There are two options for the same one is docker-compose. and another is using script. Let’s understand more in the next chapter.

--

--