Forced logout when i run a docker container - docker

When i run a new docker container (or when i start a stopped one), the system logs me out. When i login again the container is up 'n running and i can use it without any problems.
I am currently using Fedora 24.
Example:
alekos#alekos-pc:~$ docker run -d --name somename -t -p 80:80 someimage
At this point it logs me out
When I log in again I run:
alekos#alekos-pc:~$ docker ps -a
and my "somename" container is running without any further problems.
I can live with these logouts/logins but it is a bit annoying. Does anybody have any idea what is causing the problem?

Related

Docker containers won't start again after being stopped

I'm trying to launch a GitLab or Gitea docker container in my QNAP NAS (Container Station) and, for some reason, when I restart the container, it won't start back up because files are lost (it seems).
For example, for GitLab it gives me errors saying runsvdir-start and gitlab-ctl don't exist. For Gitea it's the s6-supervise file.
Now I am launching the container like this, just to keep it simple:
docker run -d --privileged --restart always gitea/gitea:latest
A simple docker stop .... and docker start .... breaks it. How do I troubleshoot something like this?
QNAP has sent this issue to R&D and they were able to replicate it. It's a bug and will probably be fixed in a new Container Station update.
It's now fixed in QTS 4.3.6.20190906 and later.
Normal to lose you data if you launch just :
docker run -d --privileged --restart always gitea/gitea:latest
You should use VOLUME to sharing folder between your host and docker host for example :
docker run -d --privileged -v ./gitea:/data -p 3000:3000 -p 222:22 --restart always gitea/gitea:latest
Or use docker-compose.yml (see the official docs).

How to save a docker container?

Whenever I am using
docker run -i -t ae8c587afa40 /bin/bash command
it always creates a new container with a new ID. Can someone help me on how to save that particular container so that whenever I exit from that container my data doesn't get lost?
You can run the container in background by using the below option:
docker run -d --hostname=quickstart.cloudera --privileged=true -t -i -p 7180:7180 -p 8888:8888 -p 10000:10000 -p 8020:8020 -p 9092:9092 -p 9093:9093 -p 9393:9393 -p 9394:9394 -p 24042:24042 4239cd2958c6 /usr/bin/docker-quickstart
The -d option will help to run the container even if you exit from the terminal on which container was started. New container id will be created. The id present in the docker run command is the image id.
Can someone help me on how to save that particular container so that whenever I exit from that container my data doesn't get lost?
You should not rely on containers re usability. Instead of executing manually commands inside a container, build your own custom image including these commands. By doing this, you do not need to worry about starting a specific container cause all containers of that image will include the commands that you have defined when building the image.
Another advantage is that you can easily share your image via its Dockerfile or by pushing it to a repository.
I suggest that you read the docs to understand docker's concept.
A docker container goes into the stopped state when you exit from the container.
You can view all docker containers (running and stopped) by using docker ps -a.
In this listing you will see your old container.
If you need to restart it you can do this:
docker start -i <container_id>
This will restart the stopped container.
See - https://docs.docker.com/engine/reference/commandline/start/ for further details on the docker start command.
Note: Having data inside a docker container is not a good idea. You should use volumes or bind mounts to save your data. A good idea is to treat containers as being ephemeral and immutable.
Edit:
To Detach from a container without exiting the shell/process running in the container use the Key sequence Control + P Control + Q.
See https://docs.docker.com/engine/reference/commandline/attach/

Docker stops previous running container with the same image. Why?

I'm on Docker for Mac 1.13.0
When I run docker run -d cassandra:3.9 each time it kills previous container. I can not start more than one instance. It works as expected with nginx:latest though, i.e. starts multiple instances.
Why is it happening?
give it a different name
docker run -d --name cassandra1 cassandra:3.9
and then
docker run -d --name cassandra2 cassandra:3.9
I suspect this might be a docker 1.13 problem. I dont see this issue on docker 1.12.6 on mac.

docker logs -f after container restart

I am using docker logs -f mycontainer to check the logs. If I restart mycontainer by docker rm -f mycontainer then docker run -d --name mycontainer, I need to use Ctrl-C then rerun the docker logs command to get the logs. I wonder if there is a better way for me to keep receiving the logs even after the container restarts.
As other commenters have mentioned, the "rm" command is destroying your container, not restarting it.
But to answer your question you could use something like this:
watch -n 0 "docker logs mycontainer"
The docker logs command doesn't keep running for a stopped container, but you can achieve a similar effect using the "watch" command. And since it's not a Docker command, it doesn't care if the container is running or not.
If you're on a Mac you might not have watch. It can be installed using pip. The same thing can be achieved with a one-liner bash script but I find watch to be much neater.
2 things
with docker rm -f mycontainer you are not stopping your container, you are killing it, then you start another brand new after
you can use docker stop mycontainer and start or simply docker restart mycontainer to keep logs.
Because container are stateless, you will lost logs if you delete your container. In that case, you have to use a volume where to write your application logs. They will be on the host instead of into your container.

Docker for Mac. docker run -d -p 80:80 --name webserver nginx shows another container with this name. but docker ps shows empty list

I am learning "Docker for Mac"
$ docker run -d -p 80:80 --name webserver nginx
docker: Error response from daemon: Conflict. The name "/webserver" is already in use by container 728da4a0a2852869c2fbfec3e3df3e575e8b4cd06cc751498d751fbaa75e8f1b. You have to remove (or rename) that container to be able to reuse that name..
But when I run
$ docker ps
It shows no containers listed.
But due to the previous error message tells me that there is this container 728da....
I removed that container
$ dockder rm 728da4a0a2852869c2fbfec3e3df3e575e8b4cd06cc751498d751fbaa75e8f1b
Now I run this statement again
$ docker run -d -p 80:80 --name webserver nginx
It is working fine this time.
And then I run $ docker ps, I can see this new container is listed
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ecc0412fd31 nginx "nginx -g 'daemon off" 19 seconds ago Up 17 seconds 0.0.0.0:80->80/tcp, 443/tcp webserver
Note:
I am using "Docker for Mac".
But I had "Docker Box" installed on the Mac before. I don't know if that is the invisible "webserver" container comes from.
As activatedgeek says in the comments, the container must have been stopped. docker ps -a shows stopped containers. Stopped containers still hold the name, along with the contents of their RW layer that shows any changes made to the RO image being used. You can reference containers by name or container id which can make typing and scripting easier. docker start webserver would have restarted the old container. docker rm webserver would remove a stopped container with that name.
You can also abbreviate the container id's to the shortest unique name to save typing or a long copy/paste. So in your example, docker rm 728d would also have removed the container.
The Docker Getting Started document asks the learners trying two statements first.
docker run hello-world
and
docker run -d -p 80:80 --name webserver nginx
I was wondering why I can run
docker run hello-world
many times but if I run
docker run -d -p 80:80 --name webserver nginx
the second time, I got the name conflicts error. Many beginners would be wondering too.
With your help and I did more search, now I understand
docker run hello-world,
we did not use --name, in this case, a random name was given so there will be no name conflicts error.
Thanks!

Resources