CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files - docker-compose

I'm trying to run linux docker on windows and getting this error.
build was fine.
'''
$ docker-compose build
Building web
Step 1/11 : FROM python:3
---> 42d620af35be
Step 2/11 : ENV PYTHONUNBUFFERED 1
---> Using cache
---> b43065732d6e
Step 3/11 : RUN apt-get update -y
---> Using cache
---> 6f65e0da9e14
Step 4/11 : RUN apt-get install -y unixodbc unixodbc-dev
---> Using cache
---> 2a9d7445a991
Step 5/11 : RUN easy_install pip
---> Using cache
---> 5994e6452e09
Step 6/11 : RUN mkdir /code
---> Using cache
---> d0eaa870fb98
Step 7/11 : WORKDIR /code
---> Using cache
---> af78d4b35f26
Step 8/11 : RUN pip uninstall django
---> Using cache
---> 92f983bfef88
Step 9/11 : COPY requirements.txt /code/
---> Using cache
---> 3c0031987286
Step 10/11 : RUN pip install -r requirements.txt
---> Using cache
---> 3915127d3d58
Step 11/11 : COPY . /code/
---> Using cache
---> de872685c733
Successfully built de872685c733
Successfully tagged djangoproject_web:latest
'''
but when i run compose up.. i see below error.
'''
$ docker-compose up
Creating djangoproject_web_1 ... done
Attaching to djangoproject_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | July 23, 2019 - 03:21:21
web_1 | Django version 2.2.3, using settings 'composeexample.settings'
web_1 | Starting development server at http://case.xxxxxx.com:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | Error: [Errno -2] Name or service not known
djangoproject_web_1 exited with code 1
'''
and if i try this
'''
docker-compose run web django-admin startproject composeexample .
'''
it says
'''
CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
'''
my Dockerfile is
'''
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN apt-get update -y
RUN apt-get install -y unixodbc unixodbc-dev
RUN easy_install pip
RUN mkdir /code
WORKDIR /code
RUN pip uninstall django
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
'''
my docker-compose.yml is
'''
version: '3'
services:
web:
build: .
command: python manage.py runserver case.xxxxxx.com:8000
volumes:
- .:/code
ports:
- "8000:8000"
'''
How can i fix the problem with composeexample? it is not even created (cause i can't see it in the folder).. your advice please.

You are probably using the docker client of Ubuntu Windows Subsystem. This gives issues with Volume feature of docker.
Run the docker run command on windows powershell and this issue will not come.

This error occurs if you try to create another project in a single virtual environment. To remove error and create next project delete "manage.py file" which is the file automatically created while starting project.
If you still get error delete the virtual environment and delete manage.py

You have 2 conflicting/overwriting statements:
In your Dockerfile:
COPY . /code/
in your docker-compose.yml:
volumes:
- .:/code
I suggest you remove the COPY statement from the Dockerfile and re-run your containers using docker-compose.
Also, you can remove the RUN command here:
RUN mkdir /code
WORKDIR /code
It is not an error, but WORKDIR already creates the folder if it doesn't exist anyway.

The problem is, you are trying to create a project that is already created by re-running the command
docker-compose run web django-admin startproject composeexample .
Just run
docker-compose run web

Related

running elixir on buildkite with docker-compose fails with dependencies

i have the following dockerfile for an elixir+phoenix app
FROM elixir:latest as build_base
RUN apt-get -y update
RUN apt-get -y install inotify-tools curl
ARG TARGETARCH
RUN if [ ${TARGETARCH} = arm64 ]; then \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-${TARGETARCH}.tar.gz \
;else \
curl -L -o /tmp/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.54.5/dart-sass-1.54.5-linux-x64.tar.gz \
;fi
RUN tar -xvf /tmp/dart-sass.tar.gz -C /tmp
RUN mv /tmp/dart-sass/sass /usr/local/bin/sass
RUN mkdir -p /app
WORKDIR /app
COPY mix.* ./
RUN mix local.hex --force
RUN mix archive.install hex phx_new --force
RUN mix local.rebar --force
RUN mix deps.clean --all
RUN mix deps.get
RUN mix --version
RUN mix deps.compile
COPY assets assets
COPY vendor vendor
COPY lib lib
COPY config config
COPY priv priv
COPY test test
RUN mix compile
the docker-compose file looks like the following
services:
web:
build:
context: .
dockerfile: Dockerfile
target: build_base
volumes:
- ./:/app
ports:
- "80:80"
command: mix phx.server
I'm trying to run docker-compose as part of the build step in buildkite, this is an extract of the step in buildkite
- label: "run web"
key: "web"
commands:
- mix phx.server
plugins:
- docker-compose#v4.9.0:
run: web
config: docker-compose.yml
however when running web i see everything happens properly including the package installation, however when running the application i see the following error
web_1 | Unchecked dependencies for environment dev:
web_1 | * telemetry_metrics (Hex package)
web_1 | the dependency is not available, run "mix deps.get"
and the list goes on and on, this works fine on my local machine, its only when running on buildkite. does anyone have any idea on how to fix this ?

How to build an image of Postgres:11 with HLL extension?

I want to make a Dockerfile to build an image of Postgres:11 that already installed postgresql-hll extension inside.
Im not experienced with Docker so Im have no idea to follow the instruction of installing this extension properly.
In order to do this you need to:
clone the git repository:
git clone https://github.com/citusdata/postgresql-hll.git
Create a file called Dockerfile (at the same level with the folder postgresql-hll created at step 1) with the contents:
ARG psversion=11
FROM postgres:$psversion
COPY postgresql-hll /postgresql-hll
RUN apt-get update -y && apt-get install -y postgresql-server-dev-${PG_MAJOR} make gcc g++
WORKDIR /postgresql-hll
RUN PG_CONFIG=/usr/bin/pg_config make
RUN PG_CONFIG=/usr/bin/pg_config make install
RUN echo "shared_preload_libraries = 'hll'" >> /usr/share/postgresql/postgresql.conf.sample
COPY create_extension.sql /docker-entrypoint-initdb.d/
Create a file create_extension.sql at the same level with the Dockerfile, with the contents:
CREATE EXTENSION hll;
Build your image:
# build for POSTGRES 11
docker build -t hll:1.0 --build-arg psversion=11 .
# build for POSTGRES 9.6
docker build -t hll:1.0 --build-arg psversion=9 .
NOTE: The version for POSTGRES 9.6 gives an error when trying to load the library. It is here for completeness and maybe somebody can contribute to fix it.
Run a container based on this image
docker run -d --name hll hll:1.0
Open a shell in the newly created container:
docker exec -ti hll bash
Inside the container run:
su postgres
psql
\dx
The output should show the hll extension as installed.

Run Kitura Docker Image causes libmysqlclient.so.18 Error

after i had some previous problem to Dockerise my MySQL Kitura SETUP here : Docker Build Kitura Sqift Container - Shim.h mysql.h file not found
I am running in a new Problem i can not solve following the Guide from : https://www.kitura.io/docs/deploying/docker.html .
After i followed all the steps and also did the fixing on the MySQL issue previously i was now able to run the following command :
docker run -p 8080:8080 -it myapp-run
THis however leads to the following issue :
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
i assume something tries again to open the libmysqclclient from some wrong Environmental Directories ?
But how can i fix this issues by building the docker images ... is there any way and better a smart way ?
Thanks a lot again for the help.
I was able to update and enhance my dockerfile this is now running smoothly and also can be used for CI and CD tasks.
FROM ibmcom/swift-ubuntu-runtime:latest
##FROM ibmcom/swift-ubuntu-runtime:5.0.1
LABEL maintainer="IBM Swift Engineering at IBM Cloud"
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu-runtime image."
# We can replace this port with what the user wants
EXPOSE 8080
# Default user if not provided
ARG bx_dev_user=root
ARG bx_dev_userid=1000
# Install system level packages
RUN apt-get update && apt-get dist-upgrade -y
RUN apt-get update && apt-get install -y sudo libmysqlclient-dev
# Add utils files
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/run-utils.sh /swift-utils/run-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /swift-utils/common-utils.sh
RUN chmod -R 555 /swift-utils
# Create user if not root
RUN if [ $bx_dev_user != "root" ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi
# Bundle application source & binaries
COPY ./.build /swift-project/.build
# Command to start Swift application
CMD [ "sh", "-c", "cd /swift-project && .build/release/Beautylivery_Server_New" ]

Docker container for app tests with postgres database

I'm new to Docker.
I'm trying to run my node app tests in a Docker container.
I want to run the tests with a real postgres db.
I'm creating this container with the following Dockerfile:
# Set image
FROM postgres:alpine
# Install node latest
RUN apk add --update nodejs nodejs-npm
# Set working dir
WORKDIR .
# Copy the current directory contents into the container at .
ADD src src
ADD .env.testing .env
ADD package.json .
ADD package-lock.json .
# Run tests
CMD npm install && npm run coverage
From the image docs, when I run the container with:
$ docker run build-name -d postgres
I see that the container takes time to start postgresql service.
When I run the container without the "-d postgres" param:
$ docker run build-name
The service does not start and the tests fail due to "could not connect to server".
Questions:
A. How can I run the tests AFTER the postgresql service starts?
B. I saw some examples using docker-composer but can I do this without composer?
Thanks
Thanks to #Bogdan I found the complete solution:
Dockerfile should be:
# Set image
FROM postgres:alpine
# Install node latest
RUN apk add --update nodejs nodejs-npm
# Set working dir
WORKDIR .
# Copy the current directory contents into the container at .
ADD src src
ADD .env.testing .env
ADD package.json .
ADD package-lock.json .
# Install
RUN npm install
# Init container
CMD psql -U postgres -c "SELECT 1;" postgres
Build container:
$ docker build -t test .
Run container:
$ docker run --name startedtest -d test -d postgres
Run tests after conatiner is running:
$ docker exec startedtest some_create_schema_script && npm run coverage
If the goal is just to run the tests in the Postgres container, one solution could be to install NodeJs in your postgres:alpine derived image and run the container normally. Once the database is up, you can run npm using docker exec like this:
docker exec <container_id> npm run coverage

issues in buiding Slate with Docker

I have tried to build slate using Docker, but modified changes are not affected when i compile the source. in my source path I have below files.
Dockerfile
FROM debian:latest
MAINTAINER Fed
VOLUME /usr/src/app/source
EXPOSE 4567
RUN apt-get update && \
apt-get install -y ruby git ruby-dev make gcc zlib1g-dev nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN gem install bundler
RUN git clone https://github.com/tripit/slate.git /slate
WORKDIR "/slate"
RUN bundle install
CMD ["bundle", "exec", "middleman", "server", "--force-polling"]
docker-compose.yml
slate:
build: .
ports:
- 4567:4567
volumes:
- ./source:/slate/source
- ./build:/slate/build
Makefile
.PHONY: build
build:
docker-compose build
up:
docker-compose up
compile:
docker-compose run slate bundle exec middleman build --clean
When I tried make compile output shows
docker-compose run slate bundle exec middleman build --clean
create build/stylesheets/screen.css
create build/stylesheets/print.css
create build/images/navbar.png
create build/images/logo.png
create build/fonts/slate.svg
create build/fonts/slate.woff
create build/fonts/slate.woff2
create build/fonts/slate.ttf
create build/fonts/slate.eot
create build/javascripts/all.js
create build/javascripts/all_nosearch.js
create build/index.html
Project built successfully
and when I execute make build
docker-compose build
Building slate
Step 1 : FROM debian:latest
---> 1b088884749b
Step 2 : MAINTAINER Fed
---> Using cache
---> f36ba5d1e018
Step 3 : VOLUME /usr/src/app/source
---> Using cache
---> d97292401c69
Step 4 : EXPOSE 4567
---> Using cache
---> 5ae0ecc71451
Step 5 : RUN apt-get update && apt-get install -y ruby git ruby-dev make gcc zlib1g-dev nodejs && apt-get clean && rm -rf /var/lib/apt/lists/*
---> Using cache
---> c83e099e40ee
Step 6 : RUN gem install bundler
---> Using cache
---> 4cc13ce89152
Step 7 : RUN git clone https://github.com/tripit/slate.git /slate
---> Using cache
---> 1ec325b7dc6b
Step 8 : WORKDIR "/slate"
---> Using cache
---> 8cc73cafc405
Step 9 : RUN bundle install
---> Using cache
---> 150ed469b196
Step 10 : CMD bundle exec middleman server --force-polling
---> Using cache
---> 9c2142617887
Successfully built 9c2142617887
and when I execute make up
docker-compose up
Starting docs_slate_1
Attaching to docs_slate_1
slate_1 | == The Middleman is loading
slate_1 | == View your site at "http://localhost:4567", "http://127.0.0.1:4567"
slate_1 | == Inspect your site configuration at "http://localhost:4567/__middleman", "http://127.0.0.1:4567/__middleman"
but when I go to browser(http://192.168.99.100:4567/- boot2docker ip) and check then it will shows original slate installation not my modified changes i have done to index.html.md file in source folder. The build folder in my path also have not been updated.
anyone can identify What i have done wrong here? I'm new to Docker.
Thanks.
Try this: docker-compose up --build