I have a docker-compose file which looks like this
version: '3'
services:
banana:
image: &banana_version recruiter-1912/banana:20.8.1
build:
context: platform
dockerfile: banana/Dockerfile
ports:
- "8000:8000"
environment:
PORT: 8000
MN_VERSION: *banana_version
volumes:
- ./platform/banana:/banana
With this file structure:
- platform/
- banana/
- Dockerfile
- requirements.txt
- banana/
-seemingly unimportant files-
- docker-compose.yml
And i am trying to deploy this service to Heroku.
I do this by doing heroku container:push web but for that i cd into the platform/banana directory.
When i try to push the container i get an error
COPY failed: stat /var/lib/docker/tmp/docker-builder648546726/banana/requirements.txt: no such file or directory
FROM python:3.7.7-slim
COPY banana/requirements.txt .
RUN pip install -r requirements.txt
ADD . /banana
WORKDIR /banana
CMD gunicorn -b :$PORT -k uvicorn.workers.UvicornWorker banana.main:app
I can deploy this to heroku if i change COPY banana/requirements.txt . to COPY requirements.txt . BUT then my docker-compose build will not work due to the same no such file or directory error.
How do i make it so i can both deploy to heroku and docker-compose build locally without needing to change the file path in dockerfile every time?
Try to change the context to ., like this:
context: .
It means your context is the current working directory.
and change
COPY banana/requirements.txt .
to
COPY platform/banana/requirements.txt .
Related
Dockerfile:
FROM node:18.13.0
ENV WORK_DIR=/app
RUN mkdir -p ${WORK_DIR}
WORKDIR ${WORK_DIR}
RUN mkdir ${WORK_DIR}/data
RUN chmod -R 755 ${WORK_DIR}/data
COPY package*.json ./
RUN npm ci
COPY . .
docker-compose.yml:
version: '3.8'
services:
fetch:
container_name: fetch
build: .
command: sh -c "npx prisma migrate deploy && npm start"
restart: unless-stopped
depends_on:
- postgres
volumes:
- ./data:/app/data:z
The container fetches new files and saves them into a directory configured by the app running in the container, defaulting to data/. The issue is that they're all created as root and cannot be manipulated by the host. If I chown the dir on the host, it works, but any new files are then created as root again.
I've tried a couple different variations of creating a new user in Dockerfile and passing host user info into the compose file but it always seems to result in a disconnect between the Dockerfile and compose file. I'm trying to keep things as easy as docker compose up, if possible.
I am new in docker. I've built an application with VueJs2 that interacts with an external API. I would like to run the application on docker.
Here is my docker-compose.yml file
version: '3'
services:
ew_cp:
image: vuejs_img
container_name: ew_cp
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- '8080:8080'
Here is my Dockerfile:
FROM node:14.17.0-alpine as develop-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN yarn install
COPY . .
EXPOSE 8080
CMD ["node"]
Here is the building command I run to build my image an container.
docker-compose up -d
The image and container is building without error but when I run the container it stops immediately. So the container is not running.
Are the DockerFile and compose files set correctly?
First of all you run npm install and yarn install, which is doing the same thing, just using different package managers. Secondly you are using CMD ["node"] which does not start your vue application, so there is no job running and docker is shutting down.
For vue applicaton you normally want to build the app with static assets and then run a simple http server to serve the static content.
FROM node:lts-alpine
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
# copy 'package.json' to install dependencies
COPY package*.json ./
# install dependencies
RUN npm install
# copy files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]
Your docker-compose file could be as simple as
version: "3.7"
services:
vue-app:
build:
context: .
dockerfile: Dockerfile
container_name: vue-app
restart: always
ports:
- "8080:8080"
networks:
- vue-network
networks:
vue-network:
driver: bridge
to run the service from docker-compose use command property in you docker-compose.yml.
services:
vue-app:
command: >
sh -c "yarn serve"
I'm not sure about the problem but by using command: tail -f /dev/null in your docker-compose file , it will keep up your container so you could track the error within it and find its problem. You could do that by running docker exec -it <CONTAINER-NAME> bash and track the error logs in your container.
version: '3'
services:
ew_cp:
image: vuejs_img
container_name: ew_cp
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
command: tail -f /dev/null
ports:
- '8080:8080'
In your Dockerfile you have to start your application e.g. npm run start or any other scripts that you are using for running your application in your package.json.
I'm new to Rasa and Docker I want to deploy my rasa project in Docker. I can't find right flow for deployment. what I understood for deployment from blogs and docker videos and tried like this.
First step: I have to create a docker image contains project source and requirements.
Dockerfile
FROM rasa/rasa
COPY . /chatbot
WORKDIR /chatbot
RUN pip install -r requirements.txt
USER root
COPY ./actions /app/actions
USER 1001
requirements.txt
pyaml
flask
requests
spacy
rasa-nlu
rasa-core
rasa-core-sdk
Second step: Create Docker-compose.yml
version: "3.0"
services:
rasa:
image: rasa/rasa:2.6.3-full
ports:
- 5005:5005
volumes:
- ./:/app
command:
- run
- -m
- models
- --enable-api
- --cors
- "*"
- --debug
action_server:
image: rasa/rasa_core_sdk:latest
ports:
- 5055:5055
volumes:
- ./actions:/app/actions
command:
- rasa
- run
- actions
Can anyone tell me right flow for deployment.
Installed docker and docker-compose on your system.
Create the first Dockerfile (just a new file with name “Dockerfile”) in root directory of the project and should have this content -
FROM rasa/rasa:2.8.0
WORKDIR '/app'
COPY . /app
USER root
# WORKDIR /app
# COPY . /app
COPY ./data /app/data
RUN rasa train
VOLUME /app
VOLUME /app/data
VOLUME /app/models
CMD ["run","-m","/app/models","--enable-api","--cors","*","--debug" ,"--endpoints", "endpoints.yml", "--log-file", "out.log", "--debug"]
Note that you can change the rasa version here.
Create second Dockerfile in actions folder and place this content -
FROM rasa/rasa-sdk:2.8.0
WORKDIR /app
COPY requirements.txt requirements.txt
USER root
RUN pip install --verbose -r requirements.txt
EXPOSE 5055
USER 1001
Note that you have to put requirements.txt file containing python libraries that you installed and used in the actions folder.
So, That was all the dockerfiles we needed, now in the root directory, you can see a file called endpoints.yml. change the name localhost to action_server (we’ll register this name in the docker-compose file for container of action server) in the action_endpoint and it should look like -
action_endpoint:
url: "http://action_server:5055/webhook"
Finally, create a docker-compose.yml file in the root directory and place these content -
version: '3'
services:
rasa:
container_name: "rasa_server"
user: root
build:
context: .
volumes:
- "./:/app"
ports:
- "5005:5005"
action_server:
container_name: "action_server"
build:
context: actions
volumes:
- ./actions:/app/actions
- ./data:/app/data
ports:
- 5055:5055
After all this you can just run the command
docker-compose up --build
credits: https://forum.rasa.com/t/dockerizing-my-rasa-chatbot-application-that-has-botfront/46096/27
It looks correct to me. I followed the same structure, except the commands in action_server (inside docker-compose.yml) . I skipped the command part, it was working fine.
action-server:
image: rasa/rasa-sdk:1.10.2
volumes:
- ./actions:/app/actions
ports:
- 5055:5055
And in endpoints url, the name of the service i.e. 'action_server' will only come
That looks like a correct way to deploy your bot using docker. What is the issue you're facing?
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
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.