Docker-compose python manage.py no such file or directory - bash

I'm using docker-compose to run three containers. Two of them depends on database so I'm using wait-for-it.sh to make sure they are not run until database is listening.
This is my docker-compose.yml file:
web:
build: ./docker/web
command: ["./wait-for-it.sh", "db:5432", "--", "python", "manage.py", "runserver", "0.0.0.0:8080"]
ports:
- "8080:8080"
depends_on:
- db
- spider
links:
- db
When I run docker-compose up command I get the error:
web_1 | wait-for-it.sh: waiting 15 seconds for db:5432
web_1 | wait-for-it.sh: db:5432 is available after 0 seconds
web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
When I add volume .:/src the manage.py is found but wait-for-it.sh isn't:
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"./wait-for-it.sh\": stat ./wait-for-it.sh: no such file or directory": unknown
I added wait-for-it.sh file to the directory where Dockerfile for web service is.
Any idea how can I make this work?
EDIT
Here's the Dockerfile used in docker-compose:
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
COPY . /src
WORKDIR /src
RUN pip install -r requirements.txt

I fixed it by changing approach. Added healthcheck to db service:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5432"]
interval: 5s
timeout: 30s
retries: 5
And restart policies to other services:
restart: on-failure

Related

Mounting Volume in DockerFile on Windows

I am working on a Springboot project with docker. I tried to mount volume so I could have access to generated files from the Springboot application in my local directory. The data is generated in the docker container but I can not find it the local directory.
I have read many topics but none seems to be helpful.
Please, I am still new to docker and would appreciate suggestions to assist.
I have tried to mount the volume directly in the dockerfile as there is a docker compose file to run the service alongside others. Below is what I have in my Dockerfile and docker-compose
Dockerfile
FROM iron/java:1.8
EXPOSE 8080
ENV USER_NAME myprofile
ENV APP_HOME /home/$USER_NAME/app
#Test Script>>>>>>>>>>>>>>>>>>>>>>
#Modifiable
ENV SQL_SCRIPT $APP_HOME/SCRIPTS_TO_RUN
ENV SQL_OUTPUT_FILE $SQL_SCRIPT/data
ENV NO_OF_USERS 3
ENV RANGE_OF_SKILLS "1-4"
ENV HOST_PATH C:"/Users/user1/IdeaProjects/path/logs"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
RUN adduser -S $USER_NAME
RUN mkdir $APP_HOME
RUN mkdir $SQL_SCRIPT
RUN chown $USER_NAME $SQL_SCRIPT
VOLUME $HOST_PATH: $SQL_SCRIPT
ADD myprofile-*.jar $APP_HOME/myprofile.jar
RUN chown $USER_NAME $APP_HOME/myprofile.jar
USER $USER_NAME
WORKDIR $APP_HOME
RUN sh -c 'touch myprofile.jar'
ENTRYPOINT ["sh", "-c","java -Djava.security.egd=file:/dev/./urandom -jar myprofile.jar -o $SQL_OUTPUT_FILE -n $NO_OF_USERS -r $RANGE_OF_SKILLS"]
Docker-compose
myprofile-backend:
extra_hosts:
- remotehost
container_name: samplecontainer-name
image: sampleimagename
links:
- rabbitmq
- db:redis
expose:
- "8080"
ports:
- "8082:8080"
volumes:
- ./logs/:/tmp/logs
- ./logs/:/app
The problem here is that you are mounting the same folder ./logs twice. Docker-compose volume mount syntax is - <your-host-path>:<your-container-path>. Also, its better to use relative paths when you are building the application. So change docker-compose file to (assuming you want to see the files in ./target relative to the Dockerfile:
myprofile-backend:
extra_hosts:
- remotehost
container_name: samplecontainer-name
image: sampleimagename
links:
- rabbitmq
- db:redis
expose:
- "8080"
ports:
- "8082:8080"
volumes:
- ./logs/:/tmp/logs
- ./target/:/app

Docker compose on Windows: no such file or directory

I'm trying to run two services with docker compose: a MySQL server and a SAMP server.
My docker-compose.yml looks like this:
version: '3.9'
services:
mysql:
image: mysql:8.0.28
volumes:
- ./mysql:/var/nw-mysql-data
env_file:
- .env
samp:
build:
context: .
dockerfile: Dockerfile
command: ./samp03svr
ports:
- "7777:7777"
env_file:
- .env
depends_on:
- mysql
And my Dockerfile:
FROM ubuntu:20.04
RUN mkdir /app
COPY . /app/
WORKDIR /app
COPY ./samp03svr /app/
The problem is in the command of the samp service. It throws the following exception when I run docker-compose up:
standard_init_linux.go:228: exec user process caused: no such file or directory
The weird thing, is that if I change the samp's command for an ls like this:
command: ls
I can see the binary file that I'm trying to execute listed, and docker is saying that there's no such file...
Help?
EDIT: Here is a screenshot of the ls command return, ran from the command instruction of the samp service:

docker is not found when running a docker command in entrypoint.sh

I'm getting
app_1 | ./entrypoint.sh: line 2: docker: command not found
when running this line of code in entrypoint.sh
docker exec -it fullstacktypescript_database_1 psql -U postgres -c "CREATE DATABASE elitypescript"
How would i properly execute this command ?
entrypoint.sh
# entrypoint.sh
docker exec -it fullstacktypescript_database_1 psql -U postgres -c "CREATE DATABASE elitypescript"
npm run seed # my attempt to run seed first before server kicks in. but doesnt work
npm run server
docker-compose.yml
# docker-compose.yml
version: "3"
services:
app:
build: ./server
depends_on:
- database
ports:
- 5000:5000
environment:
PSQL_HOST: database
PSQL_PORT: 5430
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-elitypescript}
entrypoint: ["/bin/bash", "./entrypoint.sh"]
client:
build: ./client
image: react_client
links:
- app
working_dir: /home/node/app/client
volumes:
- ./:/home/node/app
ports:
- 3001:3001
command: npm run start
env_file:
- ./client/.env
database:
image: postgres:9.6.8-alpine
volumes:
- database:/var/lib/postgresql/data
ports:
- 3030:5439
volumes:
database:
Try this Dockerfile :
FROM node:10.6.0
COPY . /home/app
WORKDIR /home/app
COPY package.json ./
RUN npm install
ENV DOCKERVERSION=18.03.1-ce
RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \
&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \
&& rm docker-${DOCKERVERSION}.tgz
EXPOSE 5000
You trying to run docker container inside of the docker container. In most cases it is very bad approach and you should to avoid it. But in case if you really need it and if you really understand what are you doing, you have to apply Docker-in-Docker(dind).
As far as I understand you, you need to run script CREATE DATABASE elitypescript, the better option will be to apply sidecar pattern - to run another one container with PostgreSQL client that will run your script.
Link the containers together and connect using the hostname.
# docker-compose
services:
app:
links:
- database
...
then just:
# entrypoint.sh
# the database container is available under the hostname database
psql -h database -p 3030 -U postgres -c "CREATE DATABASE elitypescript"
Links are a legacy option, but easier to use then networks.

running flyway migrate in docker with oracle

I have a docker file which runs an install script. it fails to find oracle connection to run migrate. in my install script i set the export to oracle home and tns directory
structure
bin
conf
docker-compose-ccpdev1.yml
Dockerfile
HOSTNAMES.md
include
INSTALL.md
install.sh
README.md
sql
my Dockerfile contains the following
# environment
ENV ORACLE_HOME="/opt/SP/instantclient_12_2"
ENV TNS_ADMIN="$ORACLE_HOME/network/admin"
ENV LD_LIBRARY_PATH="$ORACLE_HOME"
ENV PATH="$ORACLE_HOME:$TNS_ADMIN:/opt/SP/ccp-ops/bin:/opt/rh/rh-php71/root/bin:/opt/rh/rh-php71/root/sbin:/opt/rh/rh-nodejs8/root/usr/bin:$PATH"
ENV PHP_HOME="/opt/rh/rh-php71/root"
ENV https_proxy="proxy01.domain-is.de:8080"
# install
RUN yum update -y; yum install -y rh-php71 rh-php71-php-xml rh-php71-php-json rh-php71-php-ldap rh-php71-php-fpm rh-php71-php-devel rh-php71-php-opcache rh-nodejs8 libaio java wget; yum groupinstall 'Development Tools' -y; yum clean all; /root/install.sh;
VOLUME [ "/sys/fs/cgroup" ]
# run
CMD ["/usr/sbin/init"]
# ports
EXPOSE 80
EXPOSE 443
EXPOSE 8080
EXPOSE 3000
my install.sh files contains
export ORACLE_HOME=/opt/SP/instantclient_12_2
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=$PATH:$ORACLE_HOME:$TNS_ADMIN
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
export https_proxy=proxy01.domain-is.de:8080
mv /opt/SP/flyway-commandline-5.1.4.tar.gz/flyway-5.1.4 /opt/SP
rm -rf /opt/SP/flyway-commandline-5.1.4.tar.gz
mv /root/flyway.conf /opt/SP/flyway-5.1.4/conf
cp /opt/SP/instantclient_12_2/ojdbc8.jar /opt/SP/flyway-5.1.4/jars/
cd /opt/SP/flyway-5.1.4
./flyway baseline
cp /root/create_ccp_schemas.sql sql/V2__create_ccp_schemas.sql
./flyway migrate
sed -i 's/flyway\.user\=sys as sysdba/flyway\.user\=c##CCP/' conf/flyway.conf
sed -i 's/flyway\.password\=Oradoc_db1/flyway\.password\=CCP/' conf/flyway.conf
./flyway baseline -baselineVersion=2
cp /root/import_schema.sql sql/V3__import_schema.sql
sed -i 's/CCPRW/C##CCPRW/' sql/V3__import_schema.sql
sed -i 's/CCPRO/C##CCPRO/' sql/V3__import_schema.sql
./flyway migrate
cp /root/import_data.sql sql/V4__import_data.sql
sed -i 's/CCPRW/C##CCPRW/' sql/V4__import_data.sql
sed -i 's/CCPRO/C##CCPRO/' sql/V4__import_data.sql
sed -i '/REM INSERTING into/d' sql/V4__import_data.sql
sed -i '/SET DEFINE OFF/d' sql/V4__import_data.sql
error i get is
WARNING: Connection error: IO Error: could not resolve the connect identifier "ccp.oracle:1521/ORCLCDB.localdomain" (caused by could not resolve the connect identifier "ccp.oracle:1521/ORCLCDB.localdomain") Retrying in 1 sec...
...
ERROR:
Unable to obtain connection from database (jdbc:oracle:thin:#ccp.oracle:1521/ORCLCDB.localdomain) for user 'sys as sysdba': IO Error: could not resolve the connect identifier "ccp.oracle:1521/ORCLCDB.localdomain"
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State : 08006
Error Code : 17002
Message : IO Error: could not resolve the connect identifier "ccp.oracle:1521/ORCLCDB.localdomain"
i build the image using setenforce 0; docker build -t ccp-apache-php-fpm .
If i log into the docker image and run flyway manually it works. i log into image using
docker-compose -p ccpdev1 -f /root/ccp-apache-php-fpm/docker-compose-ccpdev1.yml up -d --remove-orphans
docker container exec -it ccp_app_1 /bin/bash
UPDATE
I have moved the flyway set up to post install in the docker composer file. problem i have now is it runs continuously and the container keeps restarting
dokerfile
version: '3'
services:
ccp.oracle:
container_name: ccp_oracle_1
hostname: ccp_oracle1
image: registry-beta.cdaas.domain.com/oracle/database/enterprise:12.2.0.1
restart: unless-stopped
ports:
- "33001:1521"
networks:
- backend1
ccp.app:
container_name: ccp_app_1
hostname: ccp_app1
image: ccp-apache-php-fpm
restart: unless-stopped
ports:
- "33080:80"
- "33000:3000"
links:
- ccp.oracle
command: ["./root/wait_for_oracle.sh"]
networks:
- backend1
ccp.worker:
container_name: ccp_worker_1
hostname: ccp_worker1
image: ccp-apache-php-fpm
restart: unless-stopped
links:
- ccp.app
- ccp.oracle
networks:
- backend1
ccp.jenkins:
container_name: ccp_jenkins_1
hostname: ccp_jenkins1
image: jenkins
restart: unless-stopped
ports:
- "33081:8080"
- "50001:50000"
networks:
- backend1
networks:
backend1:
driver: "bridge"

Missing Gemfile when using Docker on Heroku

I am trying out the docker plugin for Heroku, just locally to start with. When I run docker-compose up web I get the following error:
Building web
Step 1 : FROM heroku/ruby
# Executing 7 build triggers...
Step 1 : COPY Gemfile Gemfile.lock /app/user/
ERROR: Service 'web' failed to build: lstat Gemfile: no such file or directory
This is my docker-compose.yml:
web:
build: .
command: 'bash -c ''bundle exec puma -C config/puma.rb'''
working_dir: /app/user
environment:
PORT: 8080
DATABASE_URL: 'postgres://postgres:#herokuPostgresql:5432/postgres'
ports:
- '8080:8080'
links:
- herokuPostgresql
shell:
build: .
command: bash
working_dir: /app/user
environment:
PORT: 8080
DATABASE_URL: 'postgres://postgres:#herokuPostgresql:5432/postgres'
ports:
- '8080:8080'
links:
- herokuPostgresql
volumes:
- '.:/app/user'
herokuPostgresql:
image: postgres
Why is the Gemfile missing, but most importantly how should it look like for my docker?

Resources