My project's folder structure looks like:
+ cython_test/
+ ny/
+ nyc/
+ docker-compose.yml
+ Dockerfile
+ pigeon.py
+ data/
+ temps.txt
The docker-compose.yml
:
version: '2.1'
services:
worker:
build: .
volumes:
- ./:/opt
The Dockerfile
:
FROM python:3.6-alpine3.10
RUN sleep 5000
To get the container started, I do:
docker-compose -f "ny/nyc/docker-compose.yml" up -d --build
And I get the output:
Alexs-MacBook-Pro:cython_test alexvissup$ cd "/Users/alexvissup/Codes/cython_test"
Alexs-MacBook-Pro:cython_test alexvissup$ docker-compose -f "ny/nyc/docker-compose.yml" up -d --build
Creating network "nyc_default" with the default driver
Building worker
Step 1/2 : FROM python:3.6-alpine3.10
---> 92a867c54c0f
Step 2/2 : RUN sleep 5000
---> Running in fdeb933e6cfc
When I exec
into the container I expect to go into /opt
and see everything inside my local nyc
folder, but it's empty.
I'm required to specify the volumes
in the docker-compose.yml
. Is this possible? What am I doing wrong?
Docker volume will be created when the containers are created and not during the build time. Your docker file is execting a sleep command for a long time, therefore the docker-compose does not create the container until the sleep functions completely finish. (I don't see why you need the sleep at all, it is not a common thing in Docker world)
The second issue that you have here is that you do not define the container command nether in the docker-compose nor in the Dockerfile. You must define one in order to keep the container running after building the docker image.
You can try to use the below command to fix the issue (You may need to install python dependencies also )
FROM python:3.6-alpine3.10
# RUN pip install flask -- if you need to have some dependencies
WORKDIR /opt
ENTRYPOINT ["python", "pigeon.py"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.