Can't run docker container in different user - docker

I have 2 users on my ubuntu: personal and work. I created a docker image to run firefox in a container. To make things simple I added an alias in my .bash_aliases file to run it by typing "firefox" in terminal like so:
docker run --rm -d --name firefox \
-v $XDG_RUNTIME_DIR/pulse:$XDG_RUNTIME_DIR/pulse \
-e PULSE_SERVER=$XDG_RUNTIME_DIR/pulse/native \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
--network host \
shallowduck/firefox:1.0
The problem is that firefox does not launch when I'm logged in as "work" user, only "personal".
When I run the command I get container id as output in terminal but nothing launches.
When I run docker ps, the container isn't there.
When I run docker ps -a, there is no trace that the container exited with an error or whatever.
Both users are part of the docker group.
I'm not sure what I'm missing. Any ideas would be appreciated.

I fixed this by running this command in terminal:
xhost +
This adds host names on the list of machines that can connect to X server. I forgot I had to run this command for each user.

Related

What does it mean when Docker is simultaneously run in interactive and detatched modess

I'm new to Docker and came across this confusing (to me) command in one of the Docker online manuals (https://docs.docker.com/storage/bind-mounts/):
$ docker run -d \
-it \
--name devtest \
--mount type=bind,source="$(pwd)"/target,target=/app,readonly \
nginx:latest
What I found confusing was the use of both the -it flag and the -d flag. I thought -d means to run the container in the background, but -it means to allow the user to interact with the container via the current shell. What does it mean that both flags are present? What am I not understanding here?
The -i and -t flags influence how stdin and stdout are connected, even in the presence of the -d flag. Furthermore, you can always attach to a container in the future using the docker attach command.
Consider: If I try to start an interactive shell without passing -i...
$ docker run -d --name demo alpine sh
...the container will exit immediately, because stdin is closed. If I want to run that detached, I need:
$ docker run -itd --name demo alpine sh
This allows me to attach to the container in the future and interact with the shell:
$ docker attach demo
/ #

No access to volume after docker run -v

The following command runs fine on my local machine.
docker run -it --rm --ulimit memlock=-1 \
-v "$HOMEDIR/..":"/home/user/repo" \
-w "/home/user/repo/linux" \
${DOCKER_IMAGE_NAME} bash build.sh
Running it in a docker-in-docker evirionment (that means the mentioned docker command is executed in a container on google cloudbuild) is leading to two problems though:
Docker complains The input device is not a tty. My workaround: I simply used only docker run -i --rm.
Somehow the assigned volume and working directory on the container do not exist under the given path. But i checked them on the host system and they exist, but somehow do not make it until the container.
I thought also already about using docker exec but there i don't have the fancy -v options. I tried both, the docker run command with the -i and the -it flag on my local machine where it both runned fine. Anyway on cloudbuild i get the tty error when usind -it and the unacessible volume problem occurs when using -i.

why can i not run a X11 application?

So, as the title states, I'm a docker newbie.
I downloaded and installed the archlinux/base container which seems to work great so far. I've setup a few things, and installed some packages (including xeyes) and I now would like to launch xeyes. For that I found out the CONTAINER ID by running docker ps and then used that ID in my exec command which looks now like:
$ docker exec -it -e DISPLAY=$DISPLAY 4cae1ff56eb1 xeyes
Error: Can't open display: :0
Why does it still not work though? Also, how can I stop my running instance without losing its configured state? Previously I have exited the container and all my configuration and software installations were gone when I restarted it. That was not desired. How do I handle this correctly?
Concerning the X Display you need to share the xserver socket (note: docker can't bind mount a volume during an exec) and set the $DISPLAY (example Dockerfile):
FROM archlinux/base
RUN pacman -Syyu --noconfirm xorg-xeyes
ENTRYPOINT ["xeyes"]
Build the docker image: docker build --rm --network host -t so:57733715 .
Run the docker container: docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY so:57733715
Note: in case of No protocol specified errors you could disable host checking with xhost + but there is a warning to that (man xhost for additional information).

Conflict. The container name "/gitlab-runner" is already in use by container

I'm following this guide to install docker for my GitLab server running on Ubuntu 16.4.
When I execute the following command:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
So far so good. However, when I run the next command to register the runner from this guide:
docker run --rm -t -i -v /srv/gitlab-runner/config:/etc/gitlab-runner --name gitlab-runner gitlab/gitlab-runner register
I keep getting the message:
docker: Error response from daemon: Conflict. The container name "/gitlab-runner" is already in use by container "b055ded012f9d0ed085fe84756604464afbb11871b432a21300064333e34cb1d". You have to remove (or rename) that container to be able to reuse that name.
However, when I run docker container list to see the list of containers, it's empty.
Anyone know how I can fix this error?
Just to add my 2-cents as I've also recently been through those GitLab documents to get the Docker GitLab runner working.
Following the Docker image installation and configuration guide, it tells you to start that container, however that I believe, is a mistake, and you want to do that after registering the Runner.
If you did run:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
Just remove the docker container with docker rm -f gitlab-runner, and move on to registering the runner.
docker run --rm -t -i -v /srv/gitlab-runner/config:/etc/gitlab-runner --name gitlab-runner gitlab/gitlab-runner register
This would register the runner, and also place the configuration in /srv/gitlab-runner/config/config.toml on the local machine.
You can then run the original docker run:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
(NB, if this doesn't work because of the name being in use again - just run the docker rm -f gitlab-runner command again - you won't lose the gitlab-runner configuration).
And that would stand up the Docker gitlab-runner with the configuration set from the register command.
Hope this helps!
You're trying to run two containers with the same name? Where did these instructions come from? Then in your response you're saying you get the error 'No such container: gitlab-runner-config' but that's not the name of any of the containers you're trying to run?
Seems that your first container is meant to be called gitlab-runner-config based on everything else I see in there, including your volumes-from. Probably that's why gitlab-runner doesn't show up in docker ps, because you're trying to get volumes from a container that doesn't exist. Try clearing everything, and then run the following:
$ docker run -d --name gitlab-runner-config --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
...
$ docker run -d --name gitlab-runner --restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
--volumes-from gitlab-runner-config \
gitlab/gitlab-runner:latest
EDIT: OK so I read the guide, you're following the instructions wrong. It's saying in step 2, either do the one command, or the two afterwards. Either do a combined config and run container (which is called gitlab-runner) or do a config container (called gitlab-runner-config) then a runner container (called gitlab-runner). You're doing multiple steps with the same container name but mixing them up.
Run docker ps -a and you will see all your containers (even the not running ones), if you use the --rm option on run your container will be removed when stopped if that is the behaviour you are after.
You could always just skip the whole --name option if you want to create more than one of the same image and don't care about the name.
I also came across this, and opened an issue against the GitLab documentation. Here's my comment in there:
Actually, I think the issue might be something different:
On step 3, clicking on the link takes you to https://docs.gitlab.com/runner/register/index.html#docker.
In doing this, you land on the right section, near the end of the page. But this also means that you miss one important bit of information at the top of the page:
Before registering a Runner, you need to first:
Install it on a server separate than where GitLab is installed on
Obtain a token for a shared or specific Runner via GitLab's interface
That is, the documentation instructions recommend and assume that the gitlab runner container is on another machine. Thus they are not expected to work for containers on the same one.
My suggestion would be to add a note after the register step to check the registration requirements at the top of the page first.
Other than that, #johnharris85's answer would work for registering the runner on the same machine. The only extra thing you'd need to do is to add the --network="host" option to the command to do the registration. That is:
sudo docker run --rm -t -i \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
--network="host" --name gitlab-runner-register \
gitlab/gitlab-runner register

Virtualbox inside Docker

I'm trying to get VirtualBox to run inside of Docker. I'm using this: https://registry.hub.docker.com/u/jess/virtualbox/dockerfile/.
When I run the command:
sudo docker run -d \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--privileged \
--name virtualbox \
jess/virtualbox
It adds virtualbox inside a container. When I run sudo docker start container_id, it echoes back the container_id but doesn't add it to the running containers. I check with sudo docker ps and it is not there; however, it is there with sudo docker ps -a.
What am I doing wrong? I get no errors either.
EDIT: I'm running Docker in Ubuntu 15.04 (Not inside VirtualBox)
You have to let docker to connect to your local X server. There are different ways to do this. One straight way is running xhost +local:docker before running your container (i.e.: before docker run).

Resources