简体   繁体   中英

Running a docker container of a ubuntu image

New to docker.

I'm trying to run a ubuntu image container. after executing docker run ubuntu I don't find the container with docker ps . I tried docker ps -a and I found the status of the container "Exited (0) 10 seconds ago".

But by running docker docker run -itd ubuntu /bin/bash I was able to get the container running.

I don't understand why the second worked and the first not, I tried to search but I wasn't able to find an answer.

Docker is not meant to only run a single instance of images like ubuntu , but its primary usage is to run applications.

When you run docker run ubuntu , it runs ubuntu and then exits because it has no any main process to run, so quits.

But if you run docker run nginx , it's shown in docker ps , why? Because nginx has a process to make this container running.

Try this: docker run exec -it ubuntu top and docker run exec -it nginx top and see the process with ID 1. See any differences? top in ubuntu container has PID 1, but in nginx container nginx... command is the PID 1.

If you quit the top , your container kills and stops, but if you quit top in nginx , your nginx container keeps running. But whenever nginx... command kills in nginx container, the nginx container will stop too.

I recommend using other online resources to read more about Docker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM