How to launch the last docker container that I created?

When I debug my Dockerfile, y constantly need to run these two commands:

$ docker build -t myuser/myapp:mytag - < myapp.docker # to create the container
$ docker run -i -t myuser/myapp:mytag /bin/bash       # to enter the container and see what going on when something went wrong

("mytag" is usually something like "production", "testing" or "development". Not sure if I should use tags this way)

But now the second command no longer works: it starts the old container. If I list all containers with $ docker images, I see my labeled container in third place and other unlabeled containers in front of it. If I use the identifier of the 1st container, it works fine, but it will be annoying to do it this way, I have to look for its identifier every time.

What am I doing wrong?

+4
source share
3 answers

It is important to understand with regard to containers and images. It seems that your tagged image is in third place in the list of images, and you think that the first image that has only an identifier should really be tagged, but it is not. This probably means that there is a problem with creating the image. The output is docker build verbose by default and should show you the problem.

, , , - -. , . , . , , , .

+2

, :

docker start -i #ContainerID
+4

Here is what I use:

run_most_recent_container() { docker exec -it `docker ps -a --no-trunc -q | head -n 1` bash; }
0
source

Source: https://habr.com/ru/post/1532062/


All Articles