Docker compose file - docker-compose

I am new to docker and need help understanding Dockerfile.
Here is what I have currently:
version: "2"
services:
foo:
image: foo
volumes_from: ["bar"]
network_mode: "service:baz"
environment:
- "constraint:node==node-1"
bar:
image: bar
environment:
- "constraint:node==node-1"
baz:
image: baz
environment:
- "constraint:node==node-1"
I don't know how to show all field name of each service like: image, volume_from, environment etc.
Is it also possible to change environment text to myenvironment ?

Related

How to specify the image version if image is built using "build" attribute

How to specify the image version if the Dockerfile is available as part of folder foo and we use the build option to build it in docker-compose.yaml file. It says "latest" otherwise, but we want to specify something like 0.0.1
foo-gateway:
container_name: "foo-gateway"
build: foo
ports:
- 9000:80
- 9090:8080
foo/dockerfile
You can provide the image name:
foo-gateway:
container_name: "foo-gateway"
image: foo:0.0.1
build: foo
ports:
- 9000:80
- 9090:8080

Docker compose MySQL-volumes invalid invalid specification

I am using service 3 and below is mycode,
I tried to add the var- COMPOSE_CONVERT_WINDOWS_PATHS: 1 in environment
it still get the error:
ERROR: for db-on-docker-ms_mysql-dev_1 Cannot create container for service mysql-dev: invalid volume specification: '/c/Dockerfile/db-on-docker-ms:/var/lib/mysql under volumes:rw'
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- /c/Dockerfile/db-on-docker-ms:/var/lib/mysql
My Docker Version: 18.09.2
I think you either need set COMPOSE_CONVERT_WINDOWS_PATHS environment variable from your command line
$ export COMPOSE_CONVERT_WINDOWS_PATHS=1
Then change the volumes configuration
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- c:\Dockerfile\db-on-docker-ms:/var/lib/mysql
Run docker compose
$ docker-compose up
Or you can attempt to set the volumes like this
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- //c/Dockerfile/db-on-docker-ms:/var/lib/mysql
And run docker compose
$ docker-compose up
Thanks for Misantorp's ans first!
I finally figure out how to do it in windows container
the volumes path should be:
volumes:
- C:\Dockerfile\db-on-docker-ms:/var/lib/mysql
run the command in powershell:
COMPOSE_CONVERT_WINDOWS_PATHS=0
then run:
docker-compose up

with docker-compose my app container cannot see the mongodb container

Here is my docker compose file:
version: "3.3"
services:
test:
image: test
networks:
- mongo_net
ports:
- 4000:80
depends_on:
- mongodb
links:
- mongodb
mongodb:
image: mongo:latest
networks:
- mongo_net
ports:
- 27017:27017
volumes:
- local_data:/data/db
volumes:
local_data:
networks:
mongo_net:
driver: bridge
The 'test' image cannot find the 'mongodb' instance.
My assumption is that the 'links' section would connect the two, but it is not happening.
What am I missing?
for your compose file try just using depends_on. links is deprecated and maybe thats why you are currently getting issues since this is a V3 compose file.

How link a Spring boot app at existing docker container for database?

I want to use my app from a docker container with anothers docker container, one for postgres and one for solr.
My docker compose is:
version: '3'
services:
core:
build: ./core
ports:
- "8081:8081"
environment:
- "SPRING_PROFILES_ACTIVE=production"
links:
- postgresdb
- solrdb
postgresdb:
image: postgres:9.4
container_name: postgres
ports:
- "5432:5432"
environment:
- DB_DRIVER=org.postgresql.Driver
- DB_URL=jdbc:postgresql://localhost:5432/db
- DB_USERNAME=db
- DB_PASSWORD=db
networks:
default:
solrdb:
image: solr:5.5
container_name: solr
ports:
- "8983:8983"
environment:
- DB_URL=http://localhost:8984/solr
networks:
default:
networks:
default:
external:
name: mynet
And already I have containers for solr and postgres created, just I want to use it. How I can do it?
You have already exposed the ports for solrdb and the postgresdb. So in your other container access these Dbs by the container names and the exposed port.
For example, solrDb should be accessed via solrdb:8983 and
the postgresdb should be accessed via postgresdb:5432
Edit :
Make sure that both the containers are operating in the same network. You need to add this network field for all the containers.
postgresdb:
image: postgres:9.4
container_name: postgresdb
ports:
- "5432:5432"
environment:
- DB_DRIVER=org.postgresql.Driver
- DB_URL=jdbc:postgresql://localhost:5432/db
- DB_USERNAME=db
- DB_PASSWORD=db
networks:
default:
and in the end of all the docker file
networks:
default:
external:
name: <your-network-name>
And make sure that your predefined network is running prior to the start of these containers.
To create the network :
docker network create --driver overlay --scope global <your-network-name>
Note : Your container ('postgresdb') will be accessible by postgresdb:5432

docker compose port already allocated

I have three docker containers that all need access to postgres on port 5432. Running each independently I can pass -p 5432:5432 but I can't run two or more at a time because they conflict.
I'm hoping to get around this issue with docker compose but I need direction on how to do that port mapping in the yml.
This is what I have, which is not working :
version: '2'
services:
foo:
image: mynamespace/foo
ports:
- "5432:5432"
bar:
image: mynamespace/bar
ports:
- "5432:5432"
baz:
image: mynamespace/baz
ports:
- "5432:5432"
You don't need to open the port on every container. You only have to open it for your database container. Which results in something like this:
version: '2'
services:
foo:
image: mynamespace/foo
bar:
image: mynamespace/bar
baz:
image: mynamespace/baz