translate network option in docker run to docker-compose? - docker

I would like to translate the following docker command to a docker-compose file:
docker run -d --restart=always -v /var/run/docker.sock:/var/run/docker.sock --net shinyproxy-net -p 8080:8080 imshinyproxy
This is the docker-compose.yml that I wrote:
version: "3.7"
services:
shinyproxy:
image: imshinyproxy
container_name: imshinyproxy
environment:
- PUID=1000
- PGID=65537
- TZ=america/new_york
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8080:8080
networks:
- shinyproxy-net
restart: unless-stopped
Alas, when I try to run docker-compose up I get the following error:
$ docker-compose up
ERROR: Service "shinyproxy" uses an undefined network "shinyproxy-net"
I know the network exist:
$ sudo docker network create shinyproxy-net
Error response from daemon: network with name shinyproxy-net already exists
What am I doing wrong?

You must declare an external network in the networks section of your docker-compose.yml :
version: "3.7"
services:
shinyproxy:
[...]
networks:
- shinyproxy-net
networks:
shinyproxy-net:
external:
name: shinyproxy-net
networks.shinyproxy-net.external.name should correspond to the name of your previously created network.

Related

How can I translate this run docker command into docker-compose?

Trying to setup Redis from this image Redismod and struggle to translate the following code into docker-compose
$ docker run \
-p 6379:6379 \
-v /home/user/data:/data \
-v /home/user/redis.conf:/usr/local/etc/redis/redis.conf \
redislabs/redismod \
/usr/local/etc/redis/redis.conf
What I have done till now:
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes_from:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
args:
- /usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
volumes:
redis_data:
But I get the following error ERROR: Service "redis" mounts volumes from "redis_data", which is not the name of a service or container. obviously because I didn't pass the last line /usr/local/etc/redis/redis.conf
And second question, how do I translate --loadmodule and --dir from below, these aren't Redis command:
$ docker run \
-p 6379:6379 \
-v /home/user/data:/data \
redislabs/redismod \
--loadmodule /usr/lib/redis/modules/rebloom.so \
--dir /data
UPDATE
I changed my docker-compose.yml file to the following and it started to work, but it seems that Redis doesn't see the redis.conf file and continue to run in default mode, what I do wrong?
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
build:
context: .
args:
- /usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
The first error was because you used volumes_from instead of volumes. The first one is intended to get the volumes configuration from an existing container. The second one to define the volumes. In your last version redis_data is a docker volume and redis.conf is a bind mount. Your second problem is that you are using build and args that are intended to be used for building images but looks like you wanted to run a command.
Try:
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
For more info about volumes, bind mounts and docker compose reference see:
https://docs.docker.com/storage/volumes/
https://docs.docker.com/storage/bind-mounts/
https://docs.docker.com/compose/compose-file/compose-file-v3/#command

Configuring portainer(-ce) from docker-compose.yml

My docker-compose.yml:
version: "3"
services:
[...]
portainer:
image: portainer/portainer-ce
ports:
- "10280:9000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./portainer:/data"
restart: unless-stopped
command: --admin-password $$2b$$05$$XJA5Fr6FGLsptH8mb2/L2uwH2mXGDJkfbTUkpuFEnSkpWY9D2EKCO
[...]
(the "[...]" just is for other services which aren't related to the problem)
I configured the admin password with command: --admin-password [bcryptHash] but how do I configure it to use the local / "volumed" docker instance / socket from docker-compose and not from the web interface?
Try using this command
command: -H unix:///var/run/docker.sock
I found a reference to this call for the -H flag here: https://docs.portainer.io/v/ce-2.6/advanced/reverse-proxy/traefik
This contains a full docker-compose file example that sets up a reverse proxy for portainer using traefik. The relevant section is:
version: "3.3"
services:
portainer:
image: portainer/portainer-ce:2.6.3
command: -H unix:///var/run/docker.sock
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
volumes:
portainer_data:
From the official docker documentation site, there is a link to the awesome-compose repo that also has a docker-compose file example for portainer.
So from this document, it would appear that both the volume map for the socket and the command line flag are required.

Docker Compose Flags

I don't how to run the docker-compose equivalent of my code
docker run -d --name=server --restart=always --net network --ip 172.18.0.5 -p 5003:80 -v $APP_PHOTO_DIR:/app/mysql-data -v $APP_CONFIG_DIR:/app/config webserver
I've done this:
version: '3'
services:
server:
image: app-dependencies
ports:
- "5003:80"
volumes:
- ./app:/app
command: python /app/app.py
restart: always
networks:
app_net:
ipv4_address: 172.18.0.5
Are you sure you need an IP address for container? It is not recommended practice, why do you want to set it explicitly?
docker-compose.yml
version: '3'
services:
server: # correct, this would be container's name
image: webserver # this should be image name from your command line
ports:
- "5003:80" # correct, but only if you need to communicate to service from ouside
volumes: # volumes just repeat you command line, you can use Env vars
- $APP_PHOTO_DIR:/app/mysql-data
- $APP_CONFIG_DIR:/app/config
command: ["python", "/app/app.py"] # JSON notation strongly recommended
restart: always
Then docker-compose up -d and that's it. You can access your service from host with localhost:5003, no need for internal IP.
For networks, I always include in the docker-compose file, the network specification. If the network already exists, docker will not create a new one.
version: '3'
services:
server:
image: app-dependencies
ports:
- "5003:80"
volumes:
- ./app:/app
command: python /app/app.py
restart: always
networks:
app_net:
ipv4_address: 172.18.0.5
networks:
app_net:
name: NETWORK_NAME
driver: bridge
ipam:
config:
- subnet: NETWORK_SUBNET
volumes:
VOLUME_NAME:
driver:local
And you will need to add the volumes separately to match the docker run command.

Docker User-defined network is not working

I have created a bridged docker network using,
docker network create --driver bridge exa1
but when I use this network in my docker-compose and run it,
it results with this output,
ERROR: plugin "exa1" not found
I have made sure the exa1 network exists using docker network ls
and does it really exist?
Any help will be greatly appreciated!
Maybe you got a syntax error in your docker-compose.yml.
Here is my docker-compose file. Take notice on the external: true option.
version: "3"
services:
traefik:
image: traefik
container_name: traefik
command:
- --api
- --docker
- --docker.exposedbydefault=false
restart: always
ports:
- 80:80
- 8080:8080
networks:
- exa1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
exa1:
external: true

Running Cloudant as docker container with docker compose

I am trying to use this image https://hub.docker.com/r/ibmcom/cloudant-developer/ with docker compose, when I use the original instructions it works, however when I translate it to docker compose format it doesn't work properly, I see the dashboard page but it is empty and seems broken.
The original run command:
docker run \
--privileged \
--detach \
--volume cloudant:/srv \
--name cloudant-developer \
--publish 8080:80 \
--hostname cloudant.dev \
ibmcom/cloudant-developer
The compose file I created:
version: '3'
services:
cloudant:
image: ibmcom/cloudant-developer:latest
container_name: cloudant-developer
hostname: cloudant.dev
ports:
- "8080:80"
expose:
- "80"
volumes:
- cloudant:/srv
privileged: true
volumes:
cloudant:
Thanks for helping.
P.S - I do executed the commands for license agreement manually
Took me a while to figure this out. Turns out the cloudant docker container is tied to the default docker network subnet. Specifically, I found that haproxy was mapped to redirect to 172.17.0.2:5984 and was failing because by default docker compose creates a new network in a different ip range. There may be other issues related to this. Ultimately I found that you could run docker compose on the default docker network with the following config:
network_mode: bridge
So, your docker-compose.yml would look like this:
version: '3'
services:
cloudant:
image: ibmcom/cloudant-developer:latest
container_name: cloudant-developer
hostname: cloudant.dev
ports:
- "8080:80"
expose:
- "80"
volumes:
- cloudant:/srv
privileged: true
network_mode: bridge
volumes:
cloudant:

Resources