How to exit docker? - docker

I am new to docker and I exited the container's shell using exit and then used sudo docker stop ABC to kill the container. However, systemctl is-active docker still shows that docker is active. Is there any way to kill docker as well or would it remain active on my system forever?
I am using Ubuntu 18.

Docker daemon is supposed to keep running in background even if you exit and remove the container. This is because in case if you want to start a new container and docker daemon is not running then you won't be able to do it.
In case if you want to, then you can do sudo systemctl stop docker to stop the docker daemon completely. But after this if you do docker run -it someimage then you'll get an error - and to fix that you'll have to restart the docker daemon - sudo systemctl start docker
Hope that clarifies everything!

Related

How to check docker service logs when restart and stop by: sudo systemctle restart docker or sudo systemctl stop docker?

I have an ubuntu 18.04 running on a metal server. My docker working good but one day i can not build new docker image, my build script hang without showing any error (the script working good before).
I tried to restart docker engine by: sudo systemctl restart docker but docker service can not active, the command: sudo systemcle stop docker not working too.
Then i rebooted my server then docker go back.
What log files should i check to know what make my docker service hang?
You can view the docker service logs using:
sudo journalctl -fu docker.service

How to build a docker image in wsl2?

I'm using docker in wsl2. I followed this guide for the setup and everything covered therein seems to work.
Now when I try to build a docker image in wsl2 with docker build . I get the error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I assume that I have to tell docker build on which IP the docker host is running (similar to docker -H 172.20.5.64 run --rm hello-world), but I have no idea how to do this?
I had the same problem, here is the solution, that worked for me:
I had to stop docker
sudo docker service stop
I had to start docker daemon
sudo dockerd
I had to stop docker daemon by pressing ctrl + z
Than i had to move the process in the background
bg %1
Then I was able to restart docker
sudo docker service start
After that, I did no longer get an error.
I hope this works for you too.

Docker compose not doing anything

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

Starting docker service with a specific container on Ubuntu

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

Docker ps disappeared after restart system

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)

Resources