Run docker container on a Linux system. From docker ps can see all the processes.
After restart the system and run docker ps can't see some containers, but use docker ps -a can see them. Is the container still running?
If you don't set the option --restart=always when run the docker container, these containers will not be started automatically, after you restart the system.
Restart policies (–restart)
always - Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.
Refer: docker run - Restart policies (–restart)
Related
If I run this command: docker-compose up --detach:
It just returns the default information about Docker:
Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The `docker-compose up` command aggregates the output of each container. When
the command exits, all containers are stopped. Running `docker-compose up -d`
starts the containers in the background and leaves them running.
If there are existing containers for a service, and the service's configuration
or image was changed after the container's creation, `docker-compose up` picks
up the changes by stopping and recreating the containers (preserving mounted
volumes). To prevent Compose from picking up changes, use the `--no-recreate`
flag.
How can I get it to run?
I've tried docker-compose up -d, which returns:
ERROR: Couldn't connect to Docker daemon - you might need to run docker-machine start default`.
Are you sure the Docker daemon is running? Try running this:
sudo systemctl start docker
Or on older systems:
sudo service docker start
You can also use environment variables to debug what is the problem with the Docker daemon:
eval "$(docker-machine env default)"
then
docker-compose --verbose up -d
It seems Docker daemon is not running. Start it by this command (temporarily until the next reboot):
systemctl start docker
If on older OSes:
service docker start
Then run your command docker-compose up -d. If it worked, now you should enable docker so that when you reboot the OS, the daemon starts automatically:
systemctl enable docker
If on older OSes:
service docker enable
I am using docker on ubuntu and I have some containers with different projects.
Each time I start docker (sudo service docker start), all my containers are started and I just would like to start one specific container. Is that possible?
The way your container restart is handled depends on the restart policy you use when your launch your container. This is passed through the --restart option to docker run
Basically:
no option or --restart no: Do not automatically restart the container when it exits. This is the default.
--restart on-failure[:max-retries] : Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.
--restart unless-stopped: Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted.
--restart always: Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.
I used this command in order to stop launching automatically my containers when I start docker :
sudo docker update --restart=no container_name
and it works, thanks !
Yes, for sure... you can run something like :
sudo docker exec -it [interactive] frosty_brahmagupta [container name] bin/bash [here is what you want to run on docker ]
to see all your container you can run, even the inactive ones
docker ps -a
Can someone explain me why after host machine reboot all containers are exited?How can i find a way to restart containers specially rancher containers and everything be as before?
You can use the docker restart policy to control container automatic startup. Check Start containers automatically for more info.
As for the current container that are stopped you need to start them manually:
docker ps -a
docker start <container>
I was having a network issue, so I restarted my local machine, which also aborted my docker default VM. So I ran the below command to restart my virtualbox instance docker-machine restart default.
I previously had built containers on default, but I want to know, do I need to rebuild those same containers now that I restarted default, or can I just run docker-compose up?
They are not destroyed. They are stopped though. You can check with
docker ps -a
This will show all containers, stopped and running. In order to start a container
docker start <container name or container id>
I am using docker-machine with Google Compute Engine(GCE)
to run a
docker swarm cluster. I created a swarm successfully with 2
nodes
(swnd-01 & swnd-02) in the cluster. I created a daemon container
like this
in the swarm-manager environment:
docker run -d ubuntu /bin/bash
docker ps shows the container running on swnd-01. When I tried
executing a command over the container using docker exec I get the
error that container is not running while docker ps shows otherwise.
I ssh'ed into swnd-01 via docker-machine to come to know that container
exited as soon as it was created. I tried docker run command inside the
swnd-01 but it still exits. I don't understand the behavior.
Any suggestions will be thankfully received.
The reason it exits is that the /bin/bash command completes and a Docker container only runs as long as its main process (if you run such a container with the -it flags the process will keep running while the terminal is attached).
As to why the swarm manager thought the container was still running, I'm not sure. I guess there is a short delay while Swarm updates the status of everything.