Unsupported config option for services.networks: 'my_network' - docker

I am having below error while running the docker-compose file.
I have created a bridge network with name my_network
Unsupported config option for services.networks: 'my_network'
docker-compose.yml
version: '3.3'
services:
webapp1:
image: nginx:latest
container_name: my_container
ports:
- "8080:8080"
networks:
- my_network
volumes:
- /home/ajay/nginx:/www/data

That seems docker-compose configuration issue, use below docker-compose file, it will create a network and then you can use the same network in the docker-compose file.
version: '3.5'
services:
webapp1:
image: nginx:latest
container_name: my_container
ports:
- "8080:80"
networks:
- my_network
networks:
my_network:
driver: bridge
Also Nginx port should be 80 inside the container if you did not modify the default configuration.

Related

docker does not expose static ip for container

i am trying to bind container with nginx to ip 172.16.238.10 , but for some reason docker ignores settings in docker-compose
#my docker-compose file
version: "3.9"
services:
nginx:
build: nginx/
ports:
- 80:80/tcp
volumes:
./dokcer/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
./dokcer/nginx/conf/hosts:/etc/hosts
./docker/project:/var/www/project
networks:
app_net:
ipv4_address: 172.16.238.10
php-fpm:
build: php-fpm/
ports:
- 9000:9000/tcp
volumes:
./dokcer/php-fpm/conf/www.conf:/usr/local/etc/php-fpm.d/www.conf
./dokcer/php-fpm/conf/hosts:/etc/hosts
./dokcer/project:/var/www/project
networks:
app_net:
ipv4_address: 172.16.238.11
networks:
app_net:
ipam:
driver: default
config:
- subnet: "172.16.238.0/24"
after build and launch, I look at the docker_app_net network and see that the nginx container has ip 172.16.238.2 although I expected it to be 172.16.238.10.
what could be the problem? I will be grateful for every answer because I am confused :c

Docker does not support storing secrets on Windows home system using Docker toolbox

Using Docker toolbox on Windows 10 Home, Docker version 19.03, we have created a docker-compose.yml and added a secrets file as JSON, it runs fine on a Mac system, but it is unable to run the same in Windows 10 Home.
Error after running docker-compose up:
ERROR: for orthancserver Cannot create container for service orthanc: invalid mount config for type
"bind": invalid mount path: 'C:/Users/ABC/Desktop/Project/orthanc.json' mount path must be absolute
docker-compose.yml:
version: "3.7"
services:
orthanc:
image: jodogne/orthanc-plugins:1.6.1
command: /run/secrets/
container_name: orthancserver
restart: always
ports:
- "4242:4242"
- "8042:8042"
networks:
- mynetwork
volumes:
- /tmp/orthanc-db/:/var/lib/orthanc/db/
secrets:
- orthanc.json
dcserver:
build: ./dc_node_server
depends_on:
- orthanc
container_name: dcserver
restart: always
ports:
- "5001:5001"
networks:
- mynetwork
volumes:
- localdb:/database
volumes:
localdb:
external: true
networks:
mynetwork:
external: true
secrets:
orthanc.json:
file: orthanc.json
orthanc.json file kept next to docker-compose.yml
Found an alternative solution for windows 10 home, with docker toolbox. as commented by #Schwarz54, the file-sharing works well with docker volume for Dockerized Orthanc server.
Add shared folder:
Open Oracle VM manager
Go to setting of default VM
Click Shared Folders
Add C:\ drive to the list
Edit docker-compose.yml to transfer the config file to Orthanc via volume
version: "3.7"
services:
orthanc:
image: jodogne/orthanc-plugins:1.6.1
command: /run/secrets/
container_name: orthancserver
restart: always
ports:
- "4242:4242"
- "8042:8042"
networks:
- mynetwork
volumes:
- /tmp/orthanc-db/:/var/lib/orthanc/db/
- /c/Users/ABCUser/Desktop/Project/orthanc.json:/etc/orthanc/orthanc.json:ro
dcserver:
build: ./dc_node_server
depends_on:
- orthanc
container_name: dcserver
restart: always
ports:
- "5001:5001"
networks:
- mynetwork
volumes:
- localdb:/database
volumes:
localdb:
external: true
networks:
mynetwork:
external: true

docker compose issue on windows 10

I have an opensource project cloned, and it has docker-compose.yml.
I execute
docker-compose up
But I see error:
ERROR: could not find plugin bridge in v1 plugin registry: plugin not found
I even tried a commonly mentioned solution on SO:
docker network create --driver nat network-name
But issue still persists.
I understand that docker-compose is part of docker desktop install on windows.
How to solve it?
Content of the file:
version: "3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
ports: ["9200:9200"]
networks: ["sandbox"]
environment: ["discovery.type=single-node"]
kibana:
image: docker.elastic.co/kibana/kibana:6.7.0
ports: ["5601:5601"]
networks: ["sandbox"]
depends_on: ["elasticsearch"]
logstash:
image: docker.elastic.co/logstash/logstash:6.7.0
volumes:
- ./config/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
networks: ["sandbox"]
ports: ["5000:5000/udp"]
depends_on: ["elasticsearch"]
grafana:
image: grafana/grafana:6.0.2
volumes: ["./grafana/plugins/cinnamon-elasticsearch-app:/var/lib/grafana/plugins/cinnamon-elasticsearch-app"]
ports: ["3000:3000"]
networks: ["sandbox"]
depends_on: ["elasticsearch"]
networks:
sandbox:
driver: bridge

Access localhost and docker network using docker-compose

I have two different services running in a single docker-compose file. I talk to each service by referring to the service name of the containers.
Now I want my container A to access localhost as well. For this when I added the configuration of 'network_mode=host', but this creates an error now stating that container A cannot talk to container B.
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://mongo:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
For each compose file docker-compose creates a network so in this case, should I manually assign the containers to a dedicated network as well? Or is there any workaround to access both the networks?
try to add links :
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://mongo:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
links:
- mongo
#network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
and you do not need network_mode: host if you use the links
EDIT - Other solution:
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://localhost:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
network_mode: host

Docker Compose: Avoid recreation of data container

To update some images I used 'docker-compose pull'.
Then I build: 'docker-compose build'.
I wanted only to update the Application Container so I removed
it and restarted:
'docker-compose rm app' and 'docker-compose up -d app'.
But something unwanted happened. The data container was recreated too.
The old data is lost.
Dockerfile for Datacontainer:
FROM gitlab/gitlab-ce:latest
VOLUME ["/etc/gitlab", "/var/log/gitlab", "/var/opt/gitlab"]
ENTRYPOINT ["hostname"]
docker-compose.yml:
version: '2'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
domainname: example.com
hostname: gitlab
networks:
- devenv
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '80:80'
- '2224:22'
volumes_from:
- gitlabdata
gitlabdata:
build: gitlab-data
How can I avoid this next time?
The docker-compose up command has the --no-recreate flag.
This flag avoid to recreate containers if they already exists.
Therefore you can run
docker-compose up -d --no-recreate app
Your issue was because you created a volume for a container, and then removed the container, this also removed your volumes.
You should change your volumes so that they bind mount to a host directory, this way your files are stored on the host, and you can reattach to those directories incase the container goes away. Another benefit is the ability to get access to those files from the host.
Here is roughly what your compose file would look like with the new volume config.
version: '2'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
domainname: example.com
hostname: gitlab
networks:
- devenv
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '80:80'
- '2224:22'
volumes_from:
- gitlabdata
gitlabdata:
build: gitlab-data
Volumes:
- /etc/gitlab:/dir/on/host
- /var/log/gitlab:/dir/on/host2
- /var/opt/gitlab:/dir/on/host3
You can mount to what ever you want on the host. More info about volumes here: https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume
I'm facing an issue with this, in my case, always I restart the docker-compose service, the container is recreated:
My /docker-compose-app.service
[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/srv/dockercnf
ExecStart=/usr/local/bin/docker-compose up --no-recreate -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
The docker-compose.yml
version: '2'
services:
mysql2:
image: mysql/mysql-server:8.0
container_name: mysql2-container
networks:
static-network:
ipv4_address: 172.18.1.2
mysql57:
image: mysql/mysql-server:5.7
container_name: mysql57-container
networks:
static-network:
ipv4_address: 172.18.1.3
networks:
static-network:
ipam:
config:
- subnet: 172.18.0.0/16
#docker-compose v3+ do not use ip_range
ip_range: 172.18.1.0/24
I don't know what I'm missing or doing wrong.
Edited - Solved
After reading StackOverFlow Thread and getting my own conclusion, I edited my docker-compose.yml file as follows:
version: '2'
services:
mysql2:
image: mysql/mysql-server:8.0
container_name: mysql2-container
networks:
static-network:
ipv4_address: 172.18.1.2
mysql57:
image: mysql/mysql-server:5.7
container_name: mysql57-container
restart: always
volumes:
- /srv/mysql57-container:/var/lib/mysql
networks:
static-network:
ipv4_address: 172.18.1.3
networks:
static-network:
ipam:
config:
- subnet: 172.18.0.0/16
#docker-compose v3+ do not use ip_range
ip_range: 172.18.1.0/24

Resources