Docker compose can't open python file - docker

I runned docker compose file using the docker-compose up command that supposed to run some python script, but I got an error that says that he cannot open the python sciprt I gave him, this is the error:
python3: can't open file '//relay.py': [Errno 2] No such file or director
this is the full error when running the command:
image from terminal
Can someone help me fix this error?
this is my files directory:
/dockers/docker-compose.yml
/dockers/relay-codes/relay.py
/dockers/relay-codes/Dockerfile
Docker-compose.yml:
version: '3'
services:
relays:
build: ./relay-codes
volumes:
- ./relay-codes:/usr/src/app
ports:
- 5001:9898
Dockerfile:
FROM python:latest
COPY . /usr/src/app
CMD [ "python3", "./relay.py" ]

I fixed that by the following Dockerfile:
FROM python:latest
WORKDIR /usr/src/app
COPY relay.py /usr/src/app/
CMD ["python3", "relay.py"]

The exception is providing you all the clue that you need. There's no file at that location.

Related

docker build command doesn't refresh my source files

I made a typo in my source code and I noticed it after i run docker-compose up in my cli. I tried rebuilding the project but didn't change my index.js cached code.
This is my Dockerfile
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD [ "npm","start" ]
docker-compose.yml
version: '3'
services:
redis-server:
image: 'redis'
node-app:
build: .
ports:
- "4001:8081"
I recreated the image
$ sudo docker build -t phillalexakis/visits:latest .
and run
docker-composer up
It didn't change the source code at all, what have I completely missed? (I'm new with docker)
Docker-compose is looking for an image named [folder_name]_node-app, but the image you've built is tagged phillalexakis/visits.
Change your node-app service in docker-compose.yml file :
node-app:
build: .
image: node-app
And use docker-compose to build the images:
docker-compose build or docker-compose up --build

docker-compose failed to run the container

I am using this docker-compose.yml file to build an image.
Problem is when I don't use the docker-compose.yml instead use the usual docker build command, it works fine. But when I use the same Dockerfile to build the using the docker-compose it doesn't work.
This is my Dockerfile
# Use an official node runtime as a parent image
FROM node:8
WORKDIR /app/
# Install dependencies
COPY package.json /app/
RUN npm install
# Add rest of the client code
COPY . /app/
EXPOSE 3000
CMD npm start
and this is my docker-compose.yml
version: "3.2"
services:
frontend:
build: ./my-app
ports:
- 80:3000
command: npm start
Container exited right after it creates when using the docker-compose
Can someone please help me?
[Update]
This is the error I am getting

Why does docker-compose build give me no such file or directory error message

I want to setup a laravel dev environment using docker and docker-compose. And I cannot get my Dockerfile to build.
I have followed tutorials without success:
https://github.com/BretFisher/php-docker-good-defaults
https://dev.to/aschmelyun/the-beauty-of-docker-for-local-laravel-development-13c0
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
When I use sudo docker exec -it php sh
I log into the php instance and I am able to run composer install.
docker-compose.yml
build:
context: .
dockerfile: Dockerfile
container_name: php
restart: unless-stopped
tty: true
volumes:
- ./src:/var/www
ports:
- "9000:9000"
networks:
- laravel
Dockerfile
FROM php:7.0-fpm-alpine
WORKDIR /var/www
COPY composer.lock composer.json /var/www
Step 3/3 : COPY composer.lock composer.json /var/www/ ERROR: Service 'php' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder015559251/composer.lock: no such file or directory
Here is my directory structure when I terminal into the php instance.
Just in case anybody else lands up over here:
I had this line in my docker file:
COPY composer.lock composer.json /var/www
And it should have been:
'''
COPY src/composer.lock src/composer.json .
'''
Essentially your copy from path (first two arguments) is relative to the Dockerfile.
And the paste to path is relative to the WORKDIR, which was already set to /var/www.
I hope this helps, but please comment if there is anything I need to clarify.

"No Go files in..." error when i use go with docker compose

I installed Go on Ubuntu 16.04. This is my GOPATH=/home/{username}/work.
I created a project into /home/{username}/work/src.
This is my project folder hierarchy.
project-name
services
configuration
api
main.go
Dockerfile
bff
api
main.go
Dockerfile
docker-compose.yml
favicon.ico
README.md
I can build and run with my dockerfile but I can't build and up with docker-compose.
I couldn't find any solution.
Configuration service dockerfile:
FROM golang:1.11.1-alpine3.8 as builder
RUN apk update && apk add git && go get gopkg.in/natefinch/lumberjack.v2
RUN mkdir -p /go/src/project-name/services/configuration
RUN CGO_ENABLED=0
RUN GOOS=linux
ADD . /go/src/project-name/services/configuration
ENV GOPATH /go
WORKDIR /go/src/project-name/services/configuration/api
RUN go get
RUN go build
FROM alpine
RUN apk update
RUN apk add curl
RUN mkdir -p /app
COPY --from=builder /go/src/project-name/services/configuration/api/ /app/
RUN chmod +x /app/api
WORKDIR /app
EXPOSE 5001
ENTRYPOINT ["/app/api"]
It works with dockerfile.
This is my docker-compose file:
version: '3.4'
services:
bff:
image: project-name/bff:${TAG:-latest}
build:
context: .
dockerfile: services/bff/Dockerfile
ports:
- "5000:5000"
container_name: bff
depends_on:
- configuration
configuration:
image: project-name/configuration:${TAG:-latest}
build:
context: .
dockerfile: services/configuration/Dockerfile
ports:
- "5001:5001"
container_name: configuration
It didn't work.
When the “run go get” command runs, it gives an error, the error is:
can't load package: package project-name/services/configuration/api: no Go files in /go/src/project-name/services/configuration/api
ERROR: Service 'configuration' failed to build: The command '/bin/sh -c go get' returned a non-zero code: 1
In your Dockerfile, you say
ADD . /go/src/project-name/services/configuration
which expects the build context directory on the host to contain the source files. But your docker-compose.yml file says
build:
context: .
dockerfile: services/configuration/Dockerfile
where the context directory is the root of your source control tree, not the specific Go source directory you're trying to build. If you change this to
build:
context: services/configuration
# Default value of "dockerfile: Dockerfile" will be right
it will likely work better.
In plain Docker commands, your current docker-compose.yml file says the equivalent of
cd $GOPATH/src/project-name
docker build -f services/configuration/Dockerfile .
But you're probably actually running
cd $GOPATH/src/project-name/services/configuration
docker build .
and what directory is the current directory matters.

Docker-compose: How can I add a volume to a NodeJS source-code directory?

I have a NodeJS application running on a Compose service and would like to access its source-code directory from outside via volumes. I tried to do that like this:
volumes:
- "./source_code:/myApplication"
Still, when I run nodemon index.js all I get is nodemon trying to run on an empty folder, with the following error message:
Usage: nodemon [nodemon options] [script.js] [args]
See "nodemon --help" for more
I have searched around, but found no similar problems from other people. Is there a problem with the way I'm defining that volume? How would it be done properly? Thanks in advance.
It's probably an issue with your Dockerfile, the volume declaration is fine I think. See below and compare with your setup. All my files are in the same directory
# docker-compose.yml
version: "3"
services:
node-mon:
build:
context: .
dockerfile: Dockerfile
# read only volume to current directory
volumes:
- ./:/opt/app-dir:ro
Dockerfile to listen on the app.js file
#Dockerfile
FROM node:alpine
RUN mkdir -p /opt/app-dir
RUN npm install -g nodemon
WORKDIR /opt/app-dir
CMD nodemon app.js
app.js file with a console log
# app.js
console.log('it works!')

Resources