I want to use network_mode: "host" on docker-compose but it was rejected.
$ cat docker-compose.yml
version: "3.7"
services:
hello:
image: hello-world:latest
$ docker-compose up
Creating network "tmp_default" with the default driver
Creating tmp_hello_1 ... done
Attaching to tmp_hello_1
hello_1 |
hello_1 | Hello from Docker!
hello_1 | This message shows that your installation appears to be working correctly.
:
tmp_hello_1 exited with code 0
OK. Let me use network_mode: "host"
$ nano docker-compose.yml
$ cat docker-compose.yml
version: "3.7"
network_mode: "host"
services:
hello:
image: hello-world:latest
$ docker-compose up
ERROR: The Compose file './docker-compose.yml' is invalid because:
Invalid top-level property "network_mode". Valid top-level sections for this Compose file are: version, services, networks, volumes, secrets, configs, and extensions starting with "x-".
WHY!? this is official isn't it?
https://docs.docker.com/compose/compose-file/#network_mode
$ docker-compose -v
docker-compose version 1.24.1, build 4667896b
$ docker -v
Docker version 19.03.2, build 6a30dfca03
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"
network_mode is not top level property. Write it under service.
version: "3.7"
services:
hello:
network_mode: "host"
image: hello-world:latest
Related
I am trying to build service from docker file when start docker compose. The docker-compose.yml looks like:
version: '3'
services:
app:
build:
context: .
shm_size: 4gb
# ...
The build process need to enable GPU. I know how to enable GPU in deploy according to this blog. But it seems docker compose file build do not support GPU.
I think, I have read two different method.
The simple, try that:
https://docs.docker.com/compose/gpu-support/
https://www.tremplin-numerique.org/en/how-to-run-compose-docker-containers-with-gpu-access
services:
test:
image: nvidia/cuda:10.2-base
command: nvidia-smi
runtime: nvidia
The complex,
It run a docker via a run.
Then via docker compose, it connect to its docker.
In this method, it describes all steps.
https://dinhanhthi.com/docker-gpu/
docker run \
--gpus all\
--name docker_thi_test\
--rm\
-v abc:abc\
-p 8888:8888
Yaml
version: '2'
services:
jupyter:
container_name: 'docker_thi_test'
build: .
volumes:
- ./notebooks:/tf/notebooks
ports:
- 8888:8888
environment:
- NVIDIA_VISIBLE_DEVICES=0
- PASSWORD=12345
How can I check if my extra_hosts configuration is working?
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
I tried docker exec nginx /bin/sh -c 'ping host.docker.internal'
but got /bin/sh: 1: ping: not found
Is there some kind of ping alternative available in the nginx docker image?
Testing on Ubuntu 20.04.3 LTS host, with docker version 20.10.11 and docker-compose version 1.29.2.
nginx image does not come with ping command, you can add a busybox to test in and out:
cat << EOF > docker-compose.yaml
version: '3.5'
services:
nginx:
image: nginx:stable
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 8080:80
busybox:
image: busybox
extra_hosts:
- "host.docker.internal:host-gateway"
command: ash -c 'sleep 3600'
EOF
docker-compose up -d
docker-compose exec busybox ping host.docker.internal
docker-compose exec busybox wget -qO- nginx
docker-compose exec busybox wget -qO- host.docker.internal:8080
docker-compose down
Always use sidecar container & do not overwhelm the main image:
k8s community provides a good image for network debugging which includes almost all famous CLIs : dig, nslookup, ping,.etc
k8s.gcr.io/e2e-test-images/jessie-dnsutils:1.3
Use it the same way the busybox way explained by gohm'c
i am running docker on windows 10, and have a jenkins container
i can use container jenkins pipeline to build host image
docker -H host.docker.internal:2375 tag myproject:1.0 myproject:latest
i can start host container use docker-compose
docker-compose -H host.docker.internal:2375 -f /var/jenkins_home/myproject/docker-compose.yml up -d
the only issue is, if have 'volumes' in docker-compose.yml, it will display error below.
Named volume "C:\docker\myproject:/target/myproject" is used in service "myproject" but no declaration was found in the volumes section.
docker-compose.yml file
version: '3.9'
services:
myproject:
image: myproject:latest
user: root
container_name: myproject
volumes:
- C:\docker\myproject:/target/myproject
ports:
- 8080:8080
i understand it is because jenkins container cannot found 'C:\docker\myproject', but i want share this folder between host and myproject container.
i tried use below command in jenkins container but it is not working, -f only can read local container file
docker-compose -H host.docker.internal:2375 -f c:/myproject/docker-compose.yml up -d
any idea can run docker-compose with volumes in jenkins container to control host docker?
update problem solved by below
version: '3.9'
services:
myproject:
image: myproject:latest
user: root
container_name: myproject
volumes:
- type: bind
source: C:\docker\myproject
target: /target/myproject
ports:
- 8080:8080
I created a minimal docker-compose.yml file, something like this
version: '3.7'
services:
odoo:
image: odoo:14.0
container_name: odoo-app
restart: always
command:
--without-demo all
then create a new docker context using
sudo docker context create remote --docker "host=ssh://root#my-remote.server.com:2222"
i can see the new created context using
sudo docker context ls
i can connect to ssh without problem
When i try to run this deployment nothing happen
(venv) augusto#augusto-NUC10i7FNH:~/Progetti/odoo$ sudo docker-compose --verbose --context remote -f docker-compose.yml -f docker-compose.prod.yml up -d
compose.config.config.find: Using configuration files: ./docker-compose.yml,./docker-compose.prod.yml
(venv) augusto#augusto-NUC10i7FNH:~/Progetti/odoo$
why?
Both hosts (local and remote server) have Ubuntu 20.04 and the same version of docker-compose
docker-compose version 1.28.2, build unknown
docker-py version: 4.4.1
CPython version: 3.8.5
OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020
I'm new to docker and trying to understand what docker stack does. Currently trying out this container https://hub.docker.com/r/instapy/instapy
this is the docker-compose file
services:
web:
image: instapy/instapy:latest
container_name: "${COMPOSE_PROJECT_NAME}_web"
env_file: .env
environment:
- PYTHONUNBUFFERED=0
- INSTAPY_WORKSPACE=/code/InstaPy
volumes:
- ./:/code
The errors I'm getting seem to indicate quite a few issues
Ignoring deprecated options:
container_name: Setting the container name is not supported.
service "web": container_name is deprecated
service "web": env_file are ignored
Stack.compose.docker.com "test" is invalid: test: Invalid value: "null": conversion to kube entities failed: C:\Users\roole\instapy-docker\docker-compose: only absolute paths can be specified in mount source
docker compose version info
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.0.2q 20 Nov 2018
Content asked for from ' docker-compose config'
services:
web:
container_name: instapy_web
environment:
COMPOSE_PROJECT_NAME: instapy
INSTAPY_WORKSPACE: /code/InstaPy
PYTHONUNBUFFERED: '0'
image: instapy/instapy:latest
volumes:
- C:\Users\roole\instapy-docker\docker-compose:/code:rw
version: '3.0'
Any help in understanding what the hell I'm supposed to be doing would be mega.
At the beginning of each docker-compose.yml file you need to specify the version. Each version of docker-compose supports certain versions of the yml file specification.
This should work for you:
version: "3.3"
services:
web:
image: instapy/instapy:latest
container_name: "${COMPOSE_PROJECT_NAME}_web"
env_file: .env
environment:
- PYTHONUNBUFFERED=0
- INSTAPY_WORKSPACE=/code/InstaPy
volumes:
- ./:/code
When deploying a stack the container name is not relevant (in fact after version "3" is not supported). The reason for that is that docker needs to be able to change the container name in case you scale your service (multiple versions of the same container might end up running on the same docker instance and then they need to have different container names).
Also when you specify a volume you need to specify full, absolute paths. You can simply replace your volume declaration with what you got from running docker-compose config (C:\Users\roole\instapy-docker\docker-compose:/code:rw) or you can use $PWD or the equivalent for your OS to refer to your current directory