How to start docker container process after restart machine? - docker

If start a docker container like:
docker run -d -p 5000:5000 --name registry registry:2
It can be seen when run
docker ps
But after restart machine and run docker ps again, it can't been found.
When check docker ps -a can see it exist.
How to week it up at this case if don't want to kill this process to run a new one?

Docker containers don't start automatically on system boot because the Docker default restart policy is set to no.
To achieve that you shoud do:
docker update --restart=always <container ID or name>

Related

Run interactively with existing docker container

I have a container started as the following:
docker run --interactive --tty --gpus all --name my_container
--workdir "/home/ubuntu" --user ubuntu
--volume /hdd/all_cv/paiv/metis:/home/ubuntu/my --publish 8888:8888 my
how do I run interactively with my_container once I reboot my machine?
Based on the docker documentation, you can attach back to the detached container using docker attach command:
Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.
So you should try this to have an interactive session with your already running container:
docker attach my_container
If your container is stopped, you just need to start it again
docker ps -aq -f name=my_container | xargs docker start $1

docker : docker pull incendonet/centos7-mono-apache

Docker is not started even if the subsequent command is executed.
docker pull incendonet/centos7-mono-apache
Even if you check with docker ps, it does not exist.
Please tell me the cause.
Docker will be started after you run below command :
docker run -it -d image-name
docker run -it -d incendonet/centos7-mono-apache
docker pull command just fetches image from docker hub to your server/local machine. But to run it you need to use docker run.
Once it is running then it will be shown in your docker ps command and you can use below command to get into container's shell :
docker exec -it <container-id> /bin/bash

How to find/access /var/log/jasmin inside container

I have created by container with docker with the name jasmin_01 using the command
docker run -d -p 1401:1401 -p 2775:2775 -p 8990:8990 --name jasmin_01 jookies/jasmin:latest
Now, i am trying to access log files located in /var/log/jasmin inside the container by running
docker run -d -v /home/user/jasmin_logs:/var/log/jasmin --name jasmin_01 jookies/jasmin:latest
and i am getting the error
Error response from daemon: Conflict. The container name "/jasmin_01" is already in use by container "6bc05cf61a03b74f2b18d05378048e201e3f6ded768ddaf3f2660c39f9d76888". You have to remove (or rename) that container to be able to reuse that name.
How do i solve this please ?
It conflict cause container name jasmin_01 is already in use. You can check it by docker ps -a. For resolve this problem is:
docker stop jasmin_01
docker rm $(docker ps -a -q)
docker run -d -v /home/user/jasmin_logs:/var/log/jasmin --name jasmin_01 jookies/jasmin:latest
Or easiest way is change you new container name
docker run -d -v /home/user/jasmin_logs:/var/log/jasmin --name jasmin_02 jookies/jasmin:latest
The error is quite indicative of the issue: you are trying to start a new container with the same name (jasmin01). Add a unique name, stop the existing container, or remove the --name so that Docker would create a unique name automatically.
docker run --name foo runs a new container named foo
So, if you try to do it twice, you'll indeed get a duplicate name error, as you see
You probably want docker exec:
$ docker help exec
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
e.g. docker exec jasmine_01 cat /var/log/jasmine/jasmine.log

Docker exec command without the container ID

How can do something like:
docker exec -it 06a0076fb4c0 install-smt
But use the name of the container instead
docker exec -it container/container install-smt
I am running a build on CI server so I can not manually input the container ID.
How can I achieve this?
Yes, you can do this by naming the container with --name. Note that your command with container/container is likely referencing an image name and not the container.
➜ ~ docker run --name my_nginx -p 80:80 -d nginx
d122acc37d5bc2a5e03bdb836ca7b9c69670de79063db995bfd6f66b9addfcac
➜ ~ docker exec my_nginx hostname
d122acc37d5b
Although it won't save any typing, you can do something like this if you want to use the image name instead of giving the container a name:
docker run debian
docker exec -it `docker ps -q --filter ancestor=debian` bash
This will only work if you're only running one instance of the debian image.
It does help if you're constantly amending the image when working on a new Dockerfile, and wanting to repeatedly run the same command in each new container to check your changes worked as expected.
I was able to fix this by setting a container name in the docker-compose file, and rundocker exec -it with the name form the file.
#Héctor (tnx)
These steps worked for me:
This will start the container named mytapir and spawn a shell into the docker container:
docker run -d --name mytapir -it wsmoses/tapir-built:latest bash
Upon docker ps to ensure the docker container is running:
docker exec -it mytapir /bin/bash
Will spawned a shell into an existing container named mytapir.
And you can stop the container as usual docker stop mytapir.
And starting it via docker start mytapir, if it is not running.
(check via docker ps -a)

Docker start with configured ports

I have problem with Docker. I created new container using sudo docker run --name myXampp -p 41061:22 -p 41062:80 -d -v ~/Projekty/Xampp:/www pindr0p/xampp and I could access localhost:41062, but when i restarted my pc, i wanted to run docker container and again access server so I did sudo docker start myXampp but I can not access localhost:41062 anymore. Did I miss something? I even tried start with -p flags, but no success. Please help me.
Thanks
Restart your container by container Id
List all the containers who are existed or check the status of your containers after restart
docker ps -a
Then restart the container by Contaner Id
docker restart <container_id>
try to remove it competently
first please get list of dockers run as process
docker ps
then try to remove it:
docker rm <your-docker> --force
then try to run
docker ps
and make sure the docker removed
then try to
docker run blob
again
yes the container made from image again and all your new config reverted back
Stop the container using:
sudo docker stop 29ddc6836adfa14d4ec3a025fddd2e5587212fef77ba0d6edb83642a3daedd3e
and then try:
sudo docker run --name myXampp -p 41061:22 -p 41062:80 -d -v ~/Projekty/Xampp:/www pindr0p/xampp

Resources