I am using Docker Toolbox on Windows 10 Home. I am not able to see the changes in my code on the docker-container.
My docker-compose.yml file looks like this
version: "3.7"
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=MyFlaskApp
expose:
- 8080
volumes:
- ./flask:/app
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
And my Dockerfile looks like this
FROM python:3.7.2-stretch
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install the dependencies
RUN pip install -r requirements.txt
# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]
My folder structure is like this
-project
- flask
- app.ini
- Dockerfile
- requirements.txt
- run.py
-nginx
- Dockerfile
- nginx.conf
I'm pretty sure everything is in order here but I still can't make live changes to the server
Related
I Dockerkized a MENN(Nextjs) stack App, now everything works fine. I run into issues when i need to install npm packages. let me first show you the structure
src/server/Dockerfile
FROM node:14-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install -qyg nodemon#2.0.7
RUN npm install -qy
COPY . .
CMD ["npm", "run", "dev"]
src/client/Dockerfile
FROM node:14-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install -qy
COPY . .
CMD ["npm", "run", "dev"]
src/docker-compose.yml
version: "3"
services:
client:
build:
context: ./client
dockerfile: Dockerfile
ports:
- 3000:3000
networks:
- mern-network
volumes:
- ./client/src:/usr/app/src
- ./client/public:/usr/app/public
depends_on:
- server
environment:
- REACT_APP_SERVER=http://localhost:5000
- CHOKIDAR_USEPOLLING=true
command: npm run dev
stdin_open: true
tty: true
server:
build:
context: ./server
dockerfile: Dockerfile
ports:
- 5000:5000
networks:
- mern-network
volumes:
- ./server/src:/usr/app/src
depends_on:
- db
environment:
- MONGO_URL=mongodb://db:27017
- CLIENT=http://localhost:3000
command: /usr/app/node_modules/.bin/nodemon -L src/index.js
db:
image: mongo:latest
ports:
- 27017:27017
networks:
- mern-network
volumes:
- mongo-data:/data/db
networks:
mern-network:
driver: bridge
volumes:
mongo-data:
driver: local
Now if i install any packages using the host machine it is as expected updated in package.json file and if run
docker-compose build
the package.json is also updated inside the container which is fine, but i feel like this kinda breaks the whole point of having your App Dockerized! , if multiple developers need to work on this App and they all need to install node/npm in their machines whats the point of using docker other than for deployments? so what I do right now is
sudo docker exec -it cebc4bcd9af6 sh //login into server container
run a command e.g
npm i express
it installs the package and updates package.json but the host package.json is not updated and if i run the build command again all changes are lost as Dockerfile copies in the source code of host into container, is there a way to synchronize the client and host? in a way that if i install a package inside my container that should also update the host files? this way i dont need to have node/npm installed locally and fulfills the purpose of having your App Dockerized!
I created this docker-compose file based on my two images (front and back-end), both are running ok when I run docker-compose up.
The problem is that I want to make hot reload work properly for my frontend which is built upon react.
I tried many things but the properties volumes and build do not seem to be able to find my directories.
So, the directory for both projects are:
C:\Users\pwdie\Downloads\projects\typescript-api (api)
C:\Users\pwdie\Downloads\projects\frontend-api-consumer (front)
being "projects" for the root for both of them, and frontend-api-consumer containing the docker-compose.yml as the image shows.
Didn't understand that part of the docker-compose system, explanations will be well received.
Front Dockerfile
FROM node:17
WORKDIR /app
COPY package.json ./
RUN yarn
COPY ./ ./
EXPOSE 3000:3000
CMD ["yarn", "dev"]
Api Dockerfile
FROM node:17
WORKDIR /app
COPY package.json ./
RUN yarn
COPY . .
ENV DB_HOST=host.docker.internal
EXPOSE 5000:5000
CMD ["yarn", "dev"]
Docker-compose.yml
version: "3.8"
services:
api:
image: api
build: ../typescript_api
volumes:
- ../typescript_api:/var/app
environment:
DB_USER: postgres
DB_PASSWORD: postgres
DB_HOST: host.docker.internal
DB_PORT: 5432
DB_NAME: typescript_api
ACCESS_TOKEN_SECRET: 1c6c3296f699e051220674d329e040dee0abae986f62d62eb89f55dfa95bff1ac9b52731177e664e25bff9b6ce0eba6ec7a9b6cf7d03e94487dc03179dc31c7e
ports:
- "5000:5000"
front:
image: front
build: .
volumes:
- ./:/var/app
environment:
REACT_APP_MAPBOX_TOKEN: pk.eyJ1Ijoic291c2FkaWVnbzExIiwiYSI6ImNrdHEwbDRrdTBycTEycXBtbXZ5eXEzMm4ifQ.U58H7S1um_WcRC2rBoEuNw
REACT_APP_API_URL: http://localhost:5000
depends_on:
- api
ports:
- "3000:3000"
I want to build my next js project by docker tool, but I got some trouble like this:
Error: Could not find a production build in the '/var/app/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
Dockerfile:
FROM node:16-alpine
RUN mkdir -p /var/app
COPY ["./", "/var/app"]
WORKDIR /var/app
RUN npm i -g next
EXPOSE 3002
RUN npm run build
CMD ["npm", "run", "start"]
docker-compose.yml
version: '3.3'
services:
next-project:
container_name: next-project
build: ./
working_dir: /var/app
restart: 'unless-stopped'
volumes:
- ./:/var/app
env_file:
- .env
ports:
- "54000:3002"
I do run commands like this
docker-compose build && docker-compose up -d
the build was successful but when it run is failed, is there any missing configuration?
When you map your current directory to /var/app, all the files that are in that directory in the container become hidden and replaced with the files in the current directory.
Since you don't have a .next directory in the host directory, the container can't find the built files.
To get it to run, you need to remove the mapping of the current directory, so your docker-compose file becomes
version: '3.3'
services:
next-project:
container_name: next-project
build: ./
working_dir: /var/app
restart: 'unless-stopped'
env_file:
- .env
ports:
- "54000:3002"
I have a docker-compose configuration for an MEAN app that's working fine.
I would like my angular (ng serve) and express servers (nodemon) to rerun automaticaly when I hit ctrl + s as if I was running my app in local.
For that, my containers need to be aware that the files changed.
How can I do that ?
Angular's Dockerfile :
FROM node:10
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . ./
EXPOSE 4200
CMD ["npm", "start"]
Express's Dockerfile :
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . ./
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yml :
version: '3'
services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200"
express: #name of the second service
build: server # specify the directory of the Dockerfile
ports:
- "3000:3000"
links:
- database
database: # name of the third service
image: mongo
ports:
- "27017:27017"
Both Angular and Express have an .dockerignore for node_modules
If you are in dev environment, you can add the volumes section in your docker-compose.yml as below :
services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200"
volumes:
- /path/in/host/machine:/path/in/container
express: #name of the second service
build: server # specify the directory of the Dockerfile
ports:
- "3000:3000"
links:
- database
volumes:
- /path/in/host/machine:/path/in/container
database: # name of the third service
image: mongo
ports:
- "27017:27017"
Reference:
volumes in docker-compose
docker-compose up --build becomes very slow using cloud docker-machine and after one hour i have and error of a not found entrypoint.sh file.
On local Mac docker-machine same config work fine.
My docker file
FROM python:3.5.2
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD app/ /code/
ADD static/ /code/
ADD entrypoint.sh /code/
my docker compose
version: '3.7'
services:
web:
build: .
command: gunicorn --bind 0.0.0.0:8000 app.wsgi
volumes:
- .:/code
entrypoint: ./entrypoint.sh
expose:
- "80"
nginx:
image: nginx:1.15.5
restart: always
ports:
- "80:80"
volumes:
- ./static:/static
depends_on:
- web
commands I run
cd myprojectfolder
eval $(docker-machine env [my-cloud-machine-name])
docker-compose -f docker-compose.yml -f envs/prd/prd.yml up --build -d
error i have after one hour (my project files are only 40mb)
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./entrypoint.sh\": stat ./entrypoint.sh: no such file or directory": unknown
ERROR: compose.cli.main.main: Encountered errors while bringing up the project.
Please help me
Thanks
I changed as suggested to this configuration but nothing changed. I'm stuck on this:
docker.api.build._set_auth_headers: Sending auth config ()
this is my new config
docker compose
version: '3.7'
services:
web:
command: gunicorn --bind 0.0.0.0:8000 app.wsgi
entrypoint: ./entrypoint.sh
expose:
- "80"
nginx:
image: nginx:1.15.5
restart: always
ports:
- "80:80"
volumes:
- ./static:/static
depends_on:
- web
my prd.yml file
version: '3.7'
services:
web:
build:
context: .
dockerfile: ./envs/prd/Dockerfile
nginx:
volumes:
- ./envs/prd/nginx/nginx.conf /etc/nginx/nginx.conf
my prd dockerfile
FROM python:3.5.2
ENV PYTHONUNBUFFERED 1
WORKDIR /
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD app/ ./app
ADD static/ ./static
ADD envs/prd/settings.py /app/settings.py
ADD entrypoint.sh .
my .dockerignore
.DS_Store
.dockerignore
.git/
.gitignore
README.rst
README.md
*.pyc
__pycache__
.idea/*
Remove the volume declarations from your docker-compose and instead copy all relevant files in during the build stage (in your Dockerfile). For example in your web service remove volumes: .:/code and add COPY * /code to its Dockerfile.