Reputation: 2840
I downloaded centos base image executed in background as daemon and then tired to get in the terminal and couldn't get in.
My Host is Ubuntu 16.04.
Here are the steps I executed:
Host OS Version Ubuntu16.04
root@jim-Ubuntu1504:/home/jim/web# lsb_release -a No LSB modules are
available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS
Release: 16.04 Codename: xenial
root@jim-Ubuntu1504:/home/jim/web#
Started docker by following commands
root@jim-Ubuntu1504:/home/jim/web# docker run -d --name=my_centos centos
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
a3ed95caeb02: Pull complete
da71393503ec: Pull complete
Digest: sha256:1a62cd7c773dd5c6cf08e2e28596f6fcc99bd97e38c9b324163e0da90ed27562
Status: Downloaded newer image for centos:latest
63f4b8fce1bd44253bb420436da3ad5b8f532b253fc9e74ff52ad1b2f9844251
root@jim-Ubuntu1504:/home/jim/web# docker exec -i -t my_centos bash
Error response from daemon: Container 63f4b8fce1bd44253bb420436da3ad5b8f532b253fc9e74ff52ad1b2f9844251 is not running
No idea why it is exiting
root@jim-Ubuntu1504:/home/jim/web# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63f4b8fce1bd centos "/bin/bash" 18 minutes ago Exited (0) 18 minutes ago my_centos
f0ca8b9f4fa5 nginx "nginx -g 'daemon off" 23 minutes ago Up 23 minutes 80/tcp, 443/tcp my_nginxtemp
bb9ab4958c33 nginx "nginx -g 'daemon off" About an hour ago Up About an hour 80/tcp, 443/tcp boring_aryabhata
886d174f641d nginx "nginx -g 'daemon off" 2 hours ago Up 2 hours 80/tcp, 443/tcp mad_fermat
root@jim-Ubuntu1504:/home/jim/web#
Started the container but no idea why it is exiting
root@jim-Ubuntu1504:/home/jim/web# docker start 63f4b8fce1bd
63f4b8fce1bd
root@jim-Ubuntu1504:/home/jim/web# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63f4b8fce1bd centos "/bin/bash" 26 minutes ago Exited (0) 2 seconds ago my_centos
f0ca8b9f4fa5 nginx "nginx -g 'daemon off" 30 minutes ago Up 30 minutes 80/tcp, 443/tcp my_nginxtemp
bb9ab4958c33 nginx "nginx -g 'daemon off" About an hour ago Up About an hour 80/tcp, 443/tcp boring_aryabhata
886d174f641d nginx "nginx -g 'daemon off" 2 hours ago Up 2 hours 80/tcp, 443/tcp mad_fermat
root@jim-Ubuntu1504:/home/jim/web# docker exec -i -t my_centos bash
Error response from daemon: Container 63f4b8fce1bd44253bb420436da3ad5b8f532b253fc9e74ff52ad1b2f9844251 is not running
root@jim-Ubuntu1504:/home/jim/web#
PS: Can someone disable the restriction to post once every 90 mins ??? Learning has to be spontaneous and interactive.
Upvotes: 8
Views: 7938
Reputation: 1
I am facing something like that.
I downloaded ubunutu.20 image from docker hub and customized and installed so many services on that image and committed locally.
I can up a container with docker run -dt .......
But when I try to up via docker-compose.yml
it always restart.
My command: #docker run -dt --restart=always --name my_container -p 443:443 registry.mydomain.com:5000/my_image:1.0.5
and my docker.compose.yml
file.
version: "3.5"
services:
my_servicename:
image: registry.mydomain.com:5000/my_image:1.0.5
restart: always
name: my_container
ports:
- 443:443
networks:
- my_network
networks:
my_network:
driver: bridge
$ docker history -H my_image:1.0.5
IMAGE CREATED CREATED BY SIZE COMMENT
f5fe3f7a9d1f 14 hours ago /bin/bash 202MB comment-1
<missing> 14 hours ago /bin/bash 210MB comment-2
Upvotes: 0
Reputation: 32176
if you look at the Dockerfile of the latest image of CentOS, you will notice the last line, from here:
CMD ["/bin/bash"]
So you launch a container that has a shell, it exists and that is all.
Try:
docker run -it --name=my_centos centos sleep infinity
or any variant.
By the way, when you do
root@jim-Ubuntu1504:/home/jim/web# docker exec -i -t my_centos bash
you suppose that your container is running, which here, is not.
Check with:
docker ps -a --filter="name=my_centos"
that your container is up.
Upvotes: 3
Reputation: 780
You are looking for running centos
container in detached
mode.
Try the following...
sudo docker run -d -it centos
Upvotes: 8
Reputation: 955
As we try to start container, it execute bash, and bash is not able to find controlling terminal due to which docker container for centos immediately stopped as it forms. To provide it terminal as well as run it in detach mode you can use:
docker container run -it --name centos7 -d centos:latest
This will run docker container in detach mode and also assign controlling terminal to bash due to which container will not stop. Later to enter into container you can use:
docker container exec -it <container-id> bash
Upvotes: 2
Reputation: 1854
You have to run the image in interactive mode to be able to connect to it.
docker run -it centos
The -it
instructs Docker to allocate a pseudo-TTY connected to the container’s stdin; creating an interactive bash shell in the container.
You can expect this after running that command.
docker@default:~$ docker run -it centos
[root@0c3c7d59b91c /]#
Upvotes: 2