What is the equivalent of ‍-h in docker-compose? - docker

I want convert docker run to docker-compose with -h parameter
What is the equivalent of ‍‍‍‍-h in docker-compose?
My docker run command:
docker run --rm -p 8080:80/tcp -p 1935:1935 -p 3478:3478
-p 3478:3478/udp bigbluebutton -h webinar.mydomain.com
My docker-compose
version: "3"
services:
bigbluebutton:
build: .
container_name: "bigbluebutton"
restart: unless-stopped
ports:
- 1935:1935
- 3478:3478
- 3478:3478/udp
- 8080:80
networks:
public:
networks:
public:
external:
name: public

Anything that appears after the docker run image name is the Compose command:.
docker run \
--rm -p 8080:80/tcp -p 1935:1935 \ # Docker options
-p 3478:3478 -p 3478:3478/udp \ # More Docker options
bigbluebutton \ # Image name
-h webinar.mydomain.com # Command
services:
bigbluebutton:
build: .
command: -h webinar.mydomain.com
ports: ['8080:80', '1935:1935', '3478:3478', '3478:3478/udp']

Related

Docker compose passing parameters to set as environment variables of Dockerfile

The following is my Dockerfile
FROM openjdk:11.0.7-jre-slim
ARG HTTP_PORT \
NODE_NAME \
DEBUG_PORT \
JMX_PORT
ENV APP_ROOT=/root \
HTTP_PORT=$HTTP_PORT \
NODE_NAME=$NODE_NAME \
DEBUG_PORT=$DEBUG_PORT \
JMX_PORT=$JMX_PORT
ADD spring-boot-app.jar $APP_ROOT/spring-boot-app.jar
ADD Config $APP_ROOT/Config
ADD start.sh $APP_ROOT/start.sh
WORKDIR ${APP_ROOT}
CMD ["/root/start.sh"]
Contents of start.sh as follows:
#!/bin/bash
java -Dnode.name=$NODE_NAME -Dapp.port=$HTTP_PORT -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar spring-boot-app.jar
I am able to run using same image with different params as follows:
docker run -p 9261:9261 -p 65054:65054 -p 8080:8080 -itd --name=app-1 -e HTTP_PORT=8080 -e NODE_NAME=NODE1 -e DEBUG_PORT=9261 -e JMX_PORT=65054 my-image
docker run -p 9221:9221 -p 65354:65354 -p 8180:8180 -itd --name=app-2 -e HTTP_PORT=8180 -e NODE_NAME=NODE2 -e DEBUG_PORT=9221 -e JMX_PORT=65354 my-image
How to achieve this using docker-compose? I have tried the following but it is not working.
version: '3.1'
services:
app-alpha:
image: my-image
environment:
- HTTP_PORT:8080
- NODE_NAME:NODE1
- DEBUG_PORT:9261
- JMX_PORT:65054
ports:
- 9261:9261
- 65054:65054
- 8080:8080
app-beta:
image: my-image
environment:
- HTTP_PORT:8180
- NODE_NAME:NODE2
- DEBUG_PORT:9221
- JMX_PORT:65354
ports:
- 9221:9221
- 65354:65354
- 8180:8180
Replace = instead : So your variables looks:
environment:
- HTTP_PORT=8080
- NODE_NAME=NODE1
- DEBUG_PORT=9261
- JMX_PORT=65054

Running Echoip Docker Image

I'm new to Docker and having trouble running the docker image https://github.com/mpolden/echoip#docker-image. What am I doing wrong? Any help would be greatly appreciated!
$ docker run mpolden/echoip -a ./GeoLite2-ASN.mmdb -c ./GeoLite2-City.mmdb -f ./GeoLite2-Country.mmdb
echoip: open ./GeoLite2-Country.mmdb: no such file or directory
The files are in the same directory. To test on your end, download the files: GeoLite2-ASN.mmdb, GeoLite2-City.mmdb, GeoLite2-Country.mmdb: https://gofile.io/d/G4i6hb
Having a docker-compose.yml would make this much easier to run:
version: "3.7"
services:
echoip:
image: mpolden/echoip
command: "echoip -a ./GeoLite2-ASN.mmdb -c ./GeoLite2-City.mmdb -f ./GeoLite2-Country.mmdb"
ports:
- "8080:8080"
restart: unless-stopped
The files are in the same directory
Docker containers cannot access the host filesystem unless it is mounted as a volume. For example, you could mount the current directory to /data in the container...
docker run --rm -v "${PWD}:/data" -p 8080:8080 mpolden/echoip \
-a /data/GeoLite2-ASN.mmdb \
-c /data/GeoLite2-City.mmdb \
-f /data/GeoLite2-Country.mmdb \
-l 0.0.0.0:8080
A Docker Compose config might look like this
version: "3.8"
services:
echoip:
image: mpolden/echoip
command: >
-l 0.0.0.0:8080
-a /data/GeoLite2-ASN.mmdb
-c /data/GeoLite2-City.mmdb
-f /data/GeoLite2-Country.mmdb
ports:
- "8080:8080"
volumes:
- "./:/data"
restart: unless-stopped

How to convert a docker run -it bash command into a docker-compose?

Given the following command:
docker run -dit -p 9080:9080 -p 9443:9443 -p 2809:2809 -p 9043:9043 --name container_name --net=host myimage:latest bash
How to convert it into an equivalent docker-compose.yml file?
In docker-compose in -it flags are being reflected by following:
tty: true
stdin_open: true
Equivalent to docker run --net=host is this:
services:
web:
...
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
So your final docker-compose should look like this:
version: '3'
services:
my_name:
image: myimage:latest
container_name: my_name
ports:
- "9080:9080"
- "9443:9443"
- "2809:2809"
- "9043:9043"
command: bash
tty: true
stdin_open: true
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
Compose file version 3 reference
Last but not least if you want to run it in the detached mode just add -d flag to docker-compose command:
docker-compose up -d
You can’t directly. Docker Compose will start up some number of containers that are expected to run more or less autonomously, and there’s no way to start typing commands into one of them. (What would you do if you had multiple containers that you wanted to start that were all just trying to launch interactive bash sessions?)
A better design would be to set up your Docker image so that its default CMD launched the actual command you were trying to run.
FROM some_base_image:x.y
COPY ...
CMD myapp.sh
Then you should be able to run
docker run -d \
-p 9080:9080 \
-p 9443:9443 \
-p 2809:2809 \
-p 9043:9043 \
--name container_name \
myimage:latest
and your application should start up on its own, successfully, with no user intervention. That’s something you can translate directly into Docker Compose syntax and it will work as expected.

Build from linuxserver\deluge

I'd like to be able to use a Dockerfile with the linuxserver\deluge image but I'm unsure what is the correct way to do this in a docker-compose.yaml file.
docker create \
--name=deluge \
--net=host \
-e PUID=1001 \
-e PGID=1001 \
-e UMASK_SET=<022> \
-e TZ=<timezone> \
-v </path/to/deluge/config>:/config \
-v </path/to/your/downloads>:/downloads \
--restart unless-stopped \
linuxserver/deluge
Can someone help me convert this please so that I can use a Dockerfile
Thanks :)
The following docker-compose.yml file is similar to your command :
version: "3"
services:
deluge:
container_name: deluge
image: linuxserver/deluge
environment:
- PUID=1001
- PGID=1001
- UMASK_SET=<022>
- TZ=<timezone>
volumes:
- </path/to/deluge/config>:/config
- </path/to/your/downloads>:/downloads
restart: unless-stopped
network_mode: host
Documentation is a great place to find the mapping between docker options and docker-compose syntax. Here is a recap of what have been used for this example :
--name => container_name
-e => environment (array of key=value)
-v => volumes (array of volume_or_folder_on_host:/path/inside/container)
--restart <policy> => restart: <policy>
--net=xxxx => network_mode
You can now run docker-compose up to start all your services (only deluge here) instead of your docker run command.

docker: Converting docker command into docker-compose syntax

docker run --rm -it --name foo -h foo --net net1 ubuntu:latest /bin/bash
docker run --rm -it --name bar -h bar --net net1 ubuntu:latest /bin/bash
I wanted to ask how do I rewrite the command above in the docker-compose syntax?
By default docker-compose will create new bridge docker network for your setup. But if you have configured you docker network by yourself, you can specify it in your compose file, marking it as external network.
version: 3
services:
foo:
container_name: foo
image: ubuntu:latest
hostname: foo
networks:
- my_net
bar:
container_name: bar
image: ubuntu:latest
hostname: bar
networks:
- my_net
networks:
my_net:
external:
name: my_net
For
docker run --rm -it --name foo -h foo --net net1 ubuntu:latest /bin/bash
docker run --rm -it --name bar -h bar --net net1 ubuntu:latest /bin/bash
You will need to use something like below
version: 3
services:
foo:
image: ubuntu
hostname: foo
bar:
image: ubuntu
hostname: bar

Resources