10

I am getting into Docker and am trying to better understand how it works out there in the "real world".

It occurs to me that, in practice:

  • You need a way to version Docker images
  • You need a way to tell the Docker engine (running on a VM) to stop/start/restart a particular container
  • You need a way to tell the Docker engine which version of a image to run

Does Docker ship with built-in commands for handling each of these? If not what tools/strategies are used for accomplishing them? Also, when I build a Docker image (via, say, docker build -t myapp .), what file type is produced and where is it located on the machine?

smeeb
  • 27,777
  • 57
  • 250
  • 447

2 Answers2

2

docker has all you need to build images and run containers. You can create your own image by writing a Dockerfile or by pulling it from the docker hub.

In the Dockerfile you specify another image as the basis for your image, run command install things. Images can have tags, for example the ubuntu image can have the latest or 12.04 tag, that can be specified with ubuntu:latest notation.

Once you have built the image with docker build -t image-name . you can create containers from that image with `docker run --name container-name image-name.

docker ps to see running containers

docker rm <container name/id> to remove containers

Chris
  • 1,692
  • 2
  • 17
  • 21
  • 8
    I don't find this answer to be adequate, as there can be successive versions of the same tag. We need a way to be able to lock down dependencies onto a particular version of a tag. For example these tags all refer to different versions of the RMQ image: https://hub.docker.com/r/library/rabbitmq/tags/, but when someone recently made a change to the dockerfile and republished the image, it broke our prod RMQ when the docker host restarted and the latest image of that tag was pulled down. – Rene Wooller Jan 28 '16 at 04:13
  • 1
    @ReneWooller I think the answer is to not use `latest`. So in your case, start your Dockerfile with the line `FROM rabbitmq:3.6.1` – styfle Mar 18 '16 at 22:10
  • 3
    Good thinking but no, in the case I described, we were not using latest, but attempting to lock it to a particular version. There wouldn't be a problem if people tagged the versions with an additional version number for the docker file itself (eg rabbitmq:3.6.1_dv0.0.5) , but, crazily, the current standard approach is to tag on the version of whatever app the dockerfile is for. EG rabbitmq:3.6.1. The content of these tags can then change behind the scenes with no ability to lock them down, other than forking the dockerfile. – Rene Wooller Apr 15 '16 at 04:33
  • 2
    @ReneWoller Maybe this wasn't possible when you wrote this, but now you can pull a specific image version by its digest like so: docker pull rabbitmq@sha256: [ref](https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-by-digest-immutable-identifier) – Adam Georgsson Feb 25 '20 at 07:08
0

Suppose we have a docker file like bellow:

enter image description here

->Build from git without versioning: sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments

in here: fecomments is branch name and comments is the folder name.

->building from git with tag and version: sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments -t lordash/comments:v1.0

->Now if you want to build from a directory: first go to comments directory the run command sudo docker build .

->if you want to add tag you can use -t or -tag flag to do that: sudo docker build -t lordash . or sudo docker build -t lordash/comments .

-> Now you can version your image with the help of tag: sudo docker build -t lordash/comments:v1.0 .

->you can also apply multiple tag to an image: sudo docker build -t lordash/comments:latest -t lordash/comments:v1.0 .

Rafiq
  • 8,987
  • 4
  • 35
  • 35