-3

I try to create a container that has a volume between my host and the container by specifying it on my docker-compose file but after the build and the container has started impossible for me to find the folder of the volume.

Here is my docker-compose.yml

version: "3.8"
services:
  app:
    image: myworkenv:latest3
    container_name: myWorkEnv060820
    build: 
      context: .
      dockerfile: Dockerfile3
      args:
        - DISPLAY=$DISPLAY
    environment:
      - PUID=1000
      - PGID=1000
      #- DISPLAY=${DISPLAY}
      #- DISPLAY
      - MYVAR=RANDOM
    network_mode: host
    restart: unless-stopped

And here is the Dockerfile used to build the image

FROM ubuntu:20.04
ARG DISPLAY

ENV DISPLAY ${DISPLAY}
RUN apt-get update && apt-get install -y apt-utils firefox curl python python3
CMD ["/bin/bash"]

I build everything and start the container with the following script

#!/bin/bash
docker-compose -f docker-compose3.yml build
docker-compose f docker-compose3.yml up

First problem is that the container just exit so I have to run it manually like this:

docker run -it myworkenv:latest3 /bin/bash

Running it this way, when I check in the container I cannot find the folder of the volume aka /tmp/.X11-unix

On my research I have found that I could launch the container with :

docker compose run -v /tmp/.X11-unix:/tmp/.X11-unix app

This time I explicitly specify the volume on the run command (I know I could have omitted it since it is already written in the docker-compose file but anyway). However when I jump on the container I can see the folder /tmp/.X11-unix but it is not shared with the host. In fact the files inside the folder in the host do not appear in the folder in the container.

I would appreciate any help on this matter.

Note 1: In order to get the DISPLAY env variable copied in the container I has to use ARG keyword because I couldn't get it when just using environment. For example the variable MYVAR is not set in the container. It is like if the sections environment and volume are simply ignored.

4bdl
  • 9
  • 5
  • 1
    your `docker-compose.yml` does not specify `volumes` at all. Perhaps you're giving us the wrong example? – EDG956 Aug 07 '22 at 08:22
  • Also note that `docker run` doesn't look at the `docker-compose.yml` file at all, which could be a source of confusion for you. A container runs a single process, and in a Compose context it usually needs to be a long-running non-interactive process; what should that process be? – David Maze Aug 07 '22 at 09:15
  • I don't see volumes in your docker-compose please check – Shamith Wimukthi Aug 07 '22 at 10:26

1 Answers1

0

You should add this strings to your app service in docker-compose.yaml

volumes:
  - /tmp/.X11-unix:/tmp/.X11-unix