Docker Community Forums

Share and learn in the Docker community.

Docker-compose.yaml v3: Emulate the --volumes-from command

I am trying to translate the following docker commands in a docker-compose.yaml file as following:

Docker Commands:

docker run -d \
 --name x11-bridge \
 -e MODE="tcp" \
 -e XPRA_HTML="yes" \
 -e DISPLAY=:14 \
 -p 10000:10000 \
 jare/x11-bridge

docker run -d \
 --name emacs-1 \
 --volumes-from x11-bridge \
 -e DISPLAY=:14 \
 jare/emacs emacs

docker run -d \
 --name emacs-2 \
 --volumes-from x11-bridge \
 -e DISPLAY=:14 \
 jare/emacs emacs

Docker Compose:


version: "3"

services:

  # Desktop: http://localhost:10000/index.html?encoding=rgb32
  # Options: http://localhost:10000/connect.html
  x11-bridge:
    image: "jare/x11-bridge"
    stdin_open: true
    tty: true
    environment: 
      - MODE=tcp
      - XPRA_HTML=yes
      - DISPLAY=:14 
    volumes:
      - x11-bridge-pub-keys:/etc/pub-keys
      - x11-bridge-X11-unix:/tmp/.X11-unix
    ports:
      - 10000:10000 

  emacs-1:
    image: "jare/emacs"
    stdin_open: true
    tty: true
    environment: 
      - DISPLAY=:14 
    volumes:
      - x11-bridge-pub-keys:/etc/pub-keys
      - x11-bridge-X11-unix:/tmp/.X11-unix
    command: ["emacs"]
    depends_on:
      - x11-bridge

  emacs-2:
    image: "jare/emacs"
    stdin_open: true
    tty: true
    environment: 
      - DISPLAY=:14 
    volumes:
      - x11-bridge-pub-keys:/etc/pub-keys
      - x11-bridge-X11-unix:/tmp/.X11-unix
    command: ["emacs"]
    depends_on:
      - x11-bridge

volumes:
  x11-bridge-pub-keys:
  x11-bridge-X11-unix:

I got the folders that you see in the docker compose from the volumes session of a docker inspect in the x11-bridge service image.

If I go to the url http://localhost:10000/index.html?encoding=rgb32 the system will behave diferently from when I execute the docker commands directly and from when I use docker-compose up.

I believe the problem I am facing is that once I map the volumes to the x11-bridge service using docker-compose, the content already available in the x11-bridge service image is not copied to the volumes.

Please, can you let me know what am I missing here?

Best regards,
Roger

You Volumes merley share a file ment to be a unix-domain socket and the content of the /etc/pub-keys folder. The details you shared are insufficient to understand what the actual problem is (as in: what you expect and what actualy happens).

You are using named volumes with default values. Back in the days they were deleted together with the container on docker-compose down - though, I am not sure if this still is the case.

You might want to add options to either bind a folder or mount a remote share as the source for your volume declaration or create them externaly using the cli. Those are definitly permanent.

And is there a reason you use version 3 of the compose file? Unless you are aiming for swarm stack deployments, version 3 has more disadvantages than advantages. Not all configuration elements from version 2 made it into version 3.