to wrote Code
docker-compose.yml
version: '3'
services:
moinda-db:
container_name: moinda-db
image: mysql:8.0
environment:
MYSQL_DATABASE: moinda
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: moinda
MYSQL_PASSWORD: moinda
restart: always
ports:
- "3306:3306"
networks:
- moinda-local
moinda-app:
container_name: moinda-app
build:
context: ../moinda-api
dockerfile: Dockerfile
ports:
- "9090:9090"
restart: always
depends_on:
- moinda-db
networks:
- moinda-local
networks:
moinda-local:
driver: bridge
Dockerfile
FROM openjdk:11-jdk
ARG JAR_FILE=build/libs/moinda-api-1.0-SNAPSHOT.jar
ADD ${JAR_FILE} moinda.jar
ENTRYPOINT ["java", "-jar", "/moinda.jar"]
as with Title, I want to be executing command "./gradlew clean build" before build images
command syntax is not friendly yet..
try to right down command In "Dockerfile"
1.
RUN ["./gradlew", "clean", "build"]
2.
CMD ["./gradlew", "clean", "build"]
First Command is execute but failed
Second Command is not execute..
plz write comment,,
You can create a script file and do something like this:
./gradlew clean build
docker-compose up
Related
docker-compose.yml contains:
version: "3.9"
services:
build: .
web:
ports:
- "8000:8000"
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
It looks like everything after service: should be indented. Also, the service name should be before the build: . instruction. And it is best practice to use an array for the command when spaces are involved.
Try
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"
command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
volumes:
- .:/code
I have a Dockerfile and a docker-compose.yml file.
If I execute docker-compose up, it returns:
Creating network "demoapi_webnet" with the default driver
Creating demoapi_web_1 ... done
Creating d2c_postgres ... done
Attaching to demoapi_web_1, d2c_postgres
...
d2c_postgres | 2020-07-28 00:47:48.772 UTC [1] LOG: database system is ready to accept connections
But my node server is not starting.
These are my docker configuration files:
Dockerfile
FROM node:12.13-alpine As development
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm install
COPY dist .
COPY wait-for-it.sh .
CMD ["npm", "run", "start"]
docker-compose.yml
version: '3'
services:
db:
image: postgres
networks:
- webnet
container_name: "d2c_postgres"
environment:
POSTGRES_PASSWORD: 010203
POSTGRES_USER: postgres
POSTGRES_DB: demo
ports:
- "5432:5432"
web:
image: nest-app
ports:
- "3000:3000"
networks:
- webnet
environment:
DB_HOST: db
command: ["./wait-for-it.sh", "db:5432", "--", "npm", "run", "start"]
networks:
webnet:
My only clue is this line:
env: can't execute 'bash': No such file or directory
I can stablish a connection to pgadmin/postgres with that configuration, but the node server is not starting. What am I doing wrong and how can I solve it?
Wait-for-it is base on bash and it's not compatible with alpine as alpine is base on ash or sh that is why you are seeing can't execute 'bash': No such file or directory. You can look into the open issue for alpine support.
Can you make an /bin/sh version for use with alpine linux
For alpine, you can use wait-for
./wait-for is a script designed to synchronize services like docker containers. It is sh and alpine compatible.
services:
db:
image: postgres:9.4
backend:
build: backend
command: sh -c './wait-for db:5432 -- npm start'
depends_on:
- db
After big research, I found a similar issue here:
docker-compose: nodejs container not communicating with Postgres container
For some reason wait for it wasn't working (not sure if is a windows issue), that sh file is not mandatory to wait until database start, you can use depends_on to indicate that the server should start after a specified service:
version: '3'
services:
db:
image: postgres
networks:
- webnet
container_name: "node_postgres"
environment:
POSTGRES_PASSWORD: 010203
POSTGRES_USER: postgres
POSTGRES_DB: demo
ports:
- "5432:5432"
web:
image: nest-app
depends_on:
- db
ports:
- "3000:3000"
networks:
- webnet
environment:
DB_HOST: db
command: ["npm", "run", "start"]
networks:
webnet:
I have an error when I try to build :
$ docker-compose build
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.web: 'dockerfile'
Here's the content of my docker-compose.yml file :
#docker-compose.yml
version: '2'
services:
db:
image: mysql
environment:
- MYSQL_DATABASE=db
- MYSQL_ROOT_PASSWORD=pwd
volumes:
- ./mysql:/var/lib/mysql
web:
build: .
dockerfile: dev.Dockerfile
entrypoint: ./script.sh db:3306 --
command: python manage.py runserver 0.0.0.0:8000
environment:
- DJANGO_SETTINGS_MODULE=db.docker_settings
- CELERY_ALWAYS_EAGER=True
volumes:
- .:/code
- /code/node_modules/
ports:
- "8000:8000"
depends_on:
- db
I tried looking here : https://docs.docker.com/compose/compose-file/compose-file-v2/
but couldn't find any solution.
Any clue on this ? I'm still a beginner with docker.
Remove the . after build:. Also, fix your indentation, like this:
build:
context: .
dockerfile: dev.Dockerfile
entrypoint: ./script.sh db:3306 --
...
there's a problem with your indentation in docker-compose.yaml, make following changes
web:
build:
dockerfile: dev.Dockerfile
entrypoint: ./script.sh db:3306 --
command: python manage.py runserver 0.0.0.0:8000
I am trying to execute a wait-for-it.sh script in my docker-compose.yaml file using "command:". I also tried to even execute the ls command as well. They both resulted in command not found. Howeer, if I go to the command line, I am able to run both commands.
Here is the docker-compose.yaml file:
rabbitmq:
container_name: "myapp_rabbitmq"
tty: true
image: rabbitmq:management
ports:
- 15672:15672
- 15671:15671
- 5672:5672
volumes:
- /rabbitmq/lib:/var/lib/rabbitmq
- /rabbitmq/log:/var/log/rabbitmq
- /rabbitmq/conf:/etc/rabbitmq/
service1:
container_name: "service1"
build:
context: .
dockerfile: ./service1.dockerfile
links:
- mongo
- rabbitmq
depends_on:
- mongo
- rabbitmq
command: ["./wait-for-it.sh", "rabbitmq:5672", "-t", "90"]
service2:
container_name: "service2"
build:
context: .
dockerfile: ./service2.dockerfile
links:
- mongo
- rabbitmq
depends_on:
- mongo
- rabbitmq
command: ["./wait-for-it.sh", "rabbitmq:5672", "-t", "90"]
What could be causing this as the commands work from the command line, just not from docker-compose file? I am using "docker-compose up -d" to start the containers, if that helps any.
If the wait-for-it.sh is not found at runtime, then I suspect that the wait-for-it.sh is not inside your docker image.
You can add this file to the image using the ADD instruction in your Dockerfile(s)
ADD wait-for-it.sh /wait-for-it.sh
I have very limited experience with Docker, and having an issue, so I have the following yml file:
version: '2'
services:
python:
restart: always
build: .path/to/docker/file
ports:
- "5000:5000"
- "8888:8888"
links:
- db
depends_on:
- db
volumes:
- ./path/to/file/:/app:z
entrypoint:
- python
- -u
- /app/run.py
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: xxyyzz
MYSQL_DATABASE: database_name
MYSQL_USER: user_name
MYSQL_PASSWORD: xxyyzz
volumes:
- ./Dump.sql:/db/Dump.sql:z
- ./Dump_Test.sql:/db/Dump_Test.sql:z
- ./big_fc.sql:/db/big_fc.sql:z
ports:
- "3306:3306"
I need to run the following commands for the second container db:
echo '[mysqld]' >> /etc/mysql/conf.d/mysql.cnf
echo 'sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' >> /etc/mysql/conf.d/mysql.cnf
The point is that I want to run these commands just once as when you provide a docker file for the first container python. How can I achieve this?
My first advice is to build your own image with your own Dockerfile. In this case you will do it once and all the containers will have the same config.
Dockerfile should look like this:
FROM mysql:latest
COPY create_config.sh /tmp/create_config.sh
CMD ["/tmp/create_config.sh"]
Create create_config.sh in the same dir as your Dockerfile and put your required commands there:
#!/bin/bash
echo '[mysqld]' >> /etc/mysql/conf.d/mysql.cnf
echo 'sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' >> /etc/mysql/conf.d/mysql.cnf
Now you can use it in your docker-compose.yml:
db:
context: .
dockerfile: Dockerfile
Keep in mind, that context is the path to the dir where your new Dockerfile is.