I am trying to run Django-packages in Docker, but I am unable to.
I am getting the following:-
django_1 | Postgres is up - continuing...
django_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
django_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
Everything seems to be fine though.The daemon is running.
docker ps
C:\djangopackages-master>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker volume ls
C:\djangopackages-master>docker volume ls
DRIVER VOLUME NAME
local djangopackagesmaster_postgres_backup_dev
local djangopackagesmaster_postgres_data_dev
local ef5505952d82c1472e74e21a8d2921018b2f7ee5570742268c8560335fe5762b
Cant seem to figure out what might be the issue.
How i built the docker container:
Ran docker-compose -f dev.yml up after cloning the following repo.
https://github.com/djangopackages/djangopackages
Docker Files present for creation:-
https://github.com/djangopackages/djangopackages/blob/master/compose/caddy/Dockerfile
https://github.com/djangopackages/djangopackages/blob/master/compose/django/Dockerfile
https://github.com/djangopackages/djangopackages/blob/master/compose/django/Dockerfile-dev
https://github.com/djangopackages/djangopackages/blob/master/compose/postgres/Dockerfile
https://github.com/djangopackages/djangopackages/blob/master/compose/redis/Dockerfile
In this particular dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements.txt /requirements.txt
COPY ./manage.py /manage.py
RUN pip install -r /requirements.txt
COPY ./compose/django/entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r//' /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY ./compose/django/start-dev.sh /start-dev.sh
RUN sed -i 's/\r//' /start-dev.sh
RUN chmod +x /start-dev.sh
WORKDIR /app
ENTRYPOINT ["/entrypoint.sh"]
If I tell to copy manage.py as well then manage.py runs(with errors of course). It seems it is not running the manage.py in the correct path. not sure what to do here anymore.
Related
I want to spin up a low configuration containerized service for which I created a Dockerfile as below:
docker build -t apache/druid_nano:0.20.2 -f Dockerfile .
FROM ubuntu:16.04
Install Java JDK 8
RUN apt-get update
&& apt-get install -y openjdk-8-jdk
RUN mkdir /app
WORKDIR /app
COPY apache-druid-0.20.2-bin.tar.gz /app
RUN tar xvzf apache-druid-0.20.2-bin.tar.gz
WORKDIR /app/apache-druid-0.20.2
EXPOSE <PORT_NUMBERS>
ENTRYPOINT ["/bin/start/start-nano-quickstart"]
When I start the container using the command "docker run -d -p 8888:8888 apache/druid_nano:0.20.2, I get an error as below:
/bin/start-nano-quickstart: no such file or directory
I removed the ENTRYPOINT command and built the image again just to check if the file exists in the bin directory inside the container. There is a file start-nano-quickstart under the bin directory inside the container.
Am I missing anything here? Please help.
I am new in docker. I want to run my django app on port 9000. After command docker-compose up I am getting this message
Creating motion_full_version_backend_1 ... done
Attaching to motion_full_version_backend_1
backend_1 | Unknown command: 'makemigrations\r'. Did you mean makemigrations?
backend_1 | Type 'manage.py help' for usage.
backend_1 | Unknown command: 'migrate\r'. Did you mean migrate?
backend_1 | Type 'manage.py help' for usage.
" is not a valid port number or address:port pair.*
My Dockerfile :
FROM continuumio/miniconda3:latest
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update && apt-get upgrade -y && apt-get install -qqy \
wget \
bzip2 \
graphviz
RUN mkdir -p /backend
COPY ./backend/requirements.yml /backend/requirements.yml
# Create environment
RUN /opt/conda/bin/conda env create -f /backend/requirements.yml
# Add env path to environment
ENV PATH /opt/conda/envs/backend/bin:$PATH
# Activate interpreter
RUN echo "source activate backend" >~/.bashrc
# Create a scripts folder
RUN mkdir -p /scripts
COPY ./scripts /scripts
RUN chmod +x ./scripts*
COPY ./backend /backend
WORKDIR /backend
I am using script to run it
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:9000
my docker-compose.yml looks like this
version: '3'
services:
backend:
image: backend:latest
restart: always
env_file:
- ./envs/dev.env
command: 'sh /scripts/dev.sh'
ports:
- "9000:9000"
Any Ideas what I am doing wrong?
Your script has windows linefeeds within it, e.g. the \r you see in the output:
makemigrations\r
Since docker is running this command within a Linux environment, you need to adjust your script linefeeds for the Linux \n (without any \r). Linux sees those carriage returns as part of the string in the command you are running or port number you are passing. Adjust the linefeeds in your editor or using a tool like dos2unix.
I am new to docker and I was trying to create an Image for my Django application.
I have created the image using the following Dockerfile
FROM python:3.6-slim-buster
WORKDIR /app
COPY . /app
RUN pip install -r Requirements.txt
EXPOSE 8000
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver", '0.0.0.0:8000']
The problem is when I run the image using
docker run -p 8000:8000 <image-tag>
I am unable to access the app in my localhost:8000
But if I run the container using the command
docker run -p 8000:8000 <image-tag> runserver 0.0.0.0:8000
I can see my app in localhost:8000
I think that you can use only Entrypoint command.
Try with:
FROM python:3.6-slim-buster
WORKDIR /app
COPY . /app
RUN pip install -r Requirements.txt
EXPOSE 8000
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Or you can write script file (entrypoint.sh) with the line. And maybe you can run makemigrations and migrations in the same file.
You need to change the single quotes to double quotes in your CMD line.
Let's play with this simplified Dockerfile:
FROM alpine
ENTRYPOINT ["echo", "python", "manage.py"]
CMD ["runserver", '0.0.0.0:8000']
Now build it and run it:
$ docker build .
...
Successfully built 24d598ae4182
$ docker run --rm 24d598ae4182
python manage.py /bin/sh -c ["runserver", '0.0.0.0:8000']
Docker is pretty picky on the JSON-array form of the CMD, ENTRYPOINT, and RUN commands. If something doesn't parse as a JSON array, it will silently fall back to treating it as a plain command, which will get implicitly wrapped in a /bin/sh -c '...' invocation. That's what you're seeing here.
If you edit my Dockerfile to have double quotes in the CMD line and rebuild the image, then you'll see
$ docker run --rm 58114fa1fdb4
python manage.py runserver 0.0.0.0:8000
and if you actually COPY code in, use a Python base image, and delete that debugging echo, that's the command you want to execute.
Quite simple: the docker-compose configuration below does not allow any files to persist after running. So when I do docker exec -i -t aas-job-hunter_web_1 ls /app -alt, I see nothing.
Here is the (non-)working minimal example: https://github.com/philastrophist/test-docker
I'm on Windows 10, I've allowed mounted drives and enabled the TLS connection. I'm not sure what else to do. The thing that most confuses me is that requirements.txt is clearly copied over (since it installs it all) but it isn't there when I have a look docker exec.
My directory structure is:
parent/
website/
manage.py
...
Dockerfile
docker-compose.yml
...
Dockerfile:
FROM python:3.6
#WORKDIR /app
# By copying over requirements first, we make sure that Docker will cache
# our installed requirements rather than reinstall them on every build
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Now copy in our code, and run it
COPY . /app
EXPOSE 8000
CMD python website/manage.py runserver 0.0.0.0:8000
# CMD tail -f /dev/null # use when testing
docker-compose.yml:
version: '2'
services:
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
links:
- db
db:
image: "postgres:9.6"
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: hunter2
Traceback:
> docker-compose -f docker-compose.yml up --build
Building web
Step 1/6 : FROM python:3.6
---> 0668df180a32
Step 2/6 : COPY requirements.txt /app/requirements.txt
---> Using cache
---> 3073d0bef876
Step 3/6 : RUN pip install -r /app/requirements.txt
---> Using cache
---> 8ad63bbb3de5
Step 4/6 : COPY . /app
---> 16390cdd6c2c
Step 5/6 : EXPOSE 8000
---> Running in f628000e8961
Removing intermediate container f628000e8961
---> 80e6994cfbd2
Step 6/6 : CMD python website/manage.py runserver 0.0.0.0:8000
---> Running in acb6b25eb558
Removing intermediate container acb6b25eb558
---> da8876d78103
Successfully built da8876d78103
Successfully tagged aas-job-hunter_web:latest
Starting aas-job-hunter_db_1 ... done
Recreating aas-job-hunter_web_1 ... done
Attaching to aas-job-hunter_db_1, aas-job-hunter_web_1
db_1 | LOG: database system was shut down at 2019-05-24 21:23:31 UTC
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
web_1 | python: can't open file 'website/manage.py': [Errno 2] No such file or directory
aas-job-hunter_web_1 exited with code 2
Actually it copies files.
Solution 1
Change CMD to :
CMD python /app/website/manage.py runserver 0.0.0.0:8000
Solution 2
You call WORKDIR before the /app folder is created. So change your Dockerfile to :
FROM python:3.6.2
# By copying over requirements first, we make sure that Docker will cache
# our installed requirements rather than reinstall them on every build
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Now copy in our code, and run it
COPY . /app
WORKDIR /app
#EXPOSE 8000
CMD python ./website/manage.py runserver 0.0.0.0:8000
# CMD tail -f /dev/null # use when testing
And call it after.
Moreover remember that in your current docker-compose file you are using bind mounts, not volumes, so the context - . will replace entirely the content of /app in your container.
Uncomment #WORKDIR /app.
I also cleaned the other parts a bit up to utilize the WORKDIR more.
FROM python:3.6
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD python website/manage.py runserver 0.0.0.0:8000
I think there is nothing wrong with COPY. But, you need to set the work directory to /app as your manage.py file is inside /app/website, not in /website inside Docker.
So, I think your Dockerfile should be like this:
FROM python:3.6
RUN mkdir /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
COPY . /app
WORKDIR /app
EXPOSE 8000
CMD python website/manage.py runserver 0.0.0.0:8000
I have a dockerfile like this:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
ADD reports /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN ls -l /code/reports/report/manage.py # gives expected result
RUN ls -l /code/reports/build_static/ # gives expected result
RUN python /code/reports/report/manage.py build full_report.views.RenderView # does not work
Everything works fine except for the last command which runs a python package (django-bakery) through manage.py build. I don't get any errors.
This command should output some files inside build_static directory in the container.
If I ssh into the container and run the command manually then it is working. I inserted the full path with /code/ to make sure that they match and created all necessary directories beforehand.
This is how I build the container:
docker-compose run django /bin/bash
This is my docker-compose:
version: '3'
services:
django:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
I wonder how come it is working when I run the command manually through bash inside the container, but not working with the command in the dockerfile.
Thanks!
Update (it seems that the files are created, but then if I check on them they aren't there):
Step 12/12 : RUN ls -l /code/reports/build_static/
---> Running in e294563d26d5
total 11080
-rw-r--r-- 1 root root 11339956 Apr 30 10:53 index.html
drwxr-xr-x 7 root root 4096 Apr 30 10:53 static
Removing intermediate container e294563d26d5
---> b8e72da8ee5c
Successfully built b8e72da8ee5c
Successfully tagged image_django:latest
WARNING: Image for service django was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
root#7483853ecc45:/code# ls -l reports/build_static/
total 0
Try following steps and let me know output:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
ADD reports /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN ls -l /code/reports/report/manage.py # gives expected result
RUN ls -l /code/reports/build_static/ # gives expected result
RUN python /code/reports/report/manage.py build full_report.views.RenderView
RUN ls -l /code/reports/build_static/ # should give you expected list of files
Give me output for the last step.
I'll help you out based on output.
The following Dockerfile, copies your current directory content to a code folder (if it doesn't exist, it creates it), then sets it as the workdir.
The WORKDIR instruction sets the working directory for any RUN, CMD,
ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
Then, in order to reduce you docker image size to the maximum, we regroup all your commands in one RUN command so that it reduces the number of layers.
FROM python:3
ENV PYTHONUNBUFFERED 1
COPY . /code
WORKDIR /code
RUN pip install -r requirements.txt && \
ls -l reports/report/manage.py && \
ls -l reports/build_static/ && \
python reports/report/manage.py build full_report.views.RenderView
I haven't tried it with a full Django app example, but it should help you narrow down the problem !