I am developing in Visual Studio Code (Windows) using the .devcontainer. I am doing some testing using django and angular frameworks. Everything is working perfectly but when inside the container I run the command ng new angular-14-crud-example I have some problems: if after this I restart for any reason Visual Studio Code, the devcontainer does not restart anymore and returns the following error:
failed to solve: error from sender: open C:\Users\user\project\angular-14-crud-example\node_modules\make-fetch-hap
pen\node_modules\mkdirp: Access denied.
Below are the details:
Django_Dockerfile:
FROM mcr.microsoft.com/devcontainers/anaconda:0-3
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
&& rm -rf /tmp/conda-tmp
RUN pip install --upgrade pip
RUN mkdir /workspace
WORKDIR /workspace
COPY requirements.txt /workspace/
RUN pip install -r requirements.txt
COPY . /workspace/
docker-compose.yml
version: '3.8'
services:
app:
build:
context: ..
dockerfile: .devcontainer/Django_Dockerfile
env_file:
- .env
volumes:
- ../..:/workspaces:cached
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db
db:
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
env_file:
- .env
volumes:
postgres-data:
devcontainer.json:
{
"name": "Anaconda (Python 3) & PostgreSQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers-contrib/features/angular-cli:1": {}
},
}
Some deteailed error Log
[2023-01-02T13:39:52.218Z] Dev Containers 0.266.1 in VS Code 1.74.2 (e8a3071ea4344d9d48ef8a4df2c097372b0c5161).
[2023-01-02T13:39:52.218Z] Start: Resolving Remote
[2023-01-02T13:39:52.268Z] Setting up container for folder or workspace: c:\Users\user\project
[2023-01-02T13:39:52.288Z] Start: Check Docker is running
[2023-01-02T13:39:52.290Z] Start: Run: docker version --format {{.Server.APIVersion}}
[2023-01-02T13:39:53.819Z] Stop (1529 ms): Run: docker version --format {{.Server.APIVersion}}
[2023-01-02T13:39:53.820Z] Server API version: 1.41
[2023-01-02T13:39:53.823Z] Stop (1535 ms): Check Docker is running
[2023-01-02T13:39:53.825Z] Start: Run: docker volume ls -q
[2023-01-02T13:39:54.907Z] Stop (1082 ms): Run: docker volume ls -q
[2023-01-02T13:39:55.293Z] Start: Run: docker ps -q -a --filter label=vsch.local.folder=c:\Users\user\project --filter label=vsch.quality=stable
[2023-01-02T13:39:56.247Z] Stop (954 ms): Run: docker ps -q -a --filter label=vsch.local.folder=c:\Users\user\project --filter label=vsch.quality=stable
[2023-01-02T13:39:56.248Z] Start: Run: C:\Users\user\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --workspace-folder c:\Users\user\project --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\Users\user\project --log-level debug --log-format json --config c:\Users\user\project\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2023-01-02T13:39:57.189Z] (node:18596) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[2023-01-02T13:39:57.190Z] (Use `Code --trace-deprecation ...` to show where the warning was created)
[2023-01-02T13:39:57.194Z] #devcontainers/cli 0.25.2. Node.js v16.14.2. win32 10.0.19044 x64.
[2023-01-02T13:39:57.194Z] Start: Run: docker buildx version
[2023-01-02T13:39:59.057Z] Stop (1863 ms): Run: docker buildx version
[2023-01-02T13:39:59.058Z] github.com/docker/buildx v0.9.1 ed00243a0ce2a0aee75311b06e32d33b44729689
[2023-01-02T13:39:59.058Z]
[2023-01-02T13:39:59.059Z] Start: Resolving Remote
[2023-01-02T13:39:59.072Z] Start: Run: docker-compose version --short
[2023-01-02T13:40:01.002Z] Stop (1930 ms): Run: docker-compose version --short
[2023-01-02T13:40:01.003Z] Docker Compose version: 2.12.0
[2023-01-02T13:40:01.006Z] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=mydemo_devcontainer --filter label=com.docker.compose.service=app
[2023-01-02T13:40:02.023Z] Stop (1017 ms): Run: docker ps -q -a --filter label=com.docker.compose.project=mydemo_devcontainer --filter label=com.docker.compose.service=app
[2023-01-02T13:40:02.026Z] Start: Run: docker-compose -f c:\Users\user\project\.devcontainer\docker-compose.yml --profile * config
[2023-01-02T13:40:03.955Z] Stop (1929 ms): Run: docker-compose -f c:\Users\user\project\.devcontainer\docker-compose.yml --profile * config
[2023-01-02T13:40:03.955Z] name: devcontainer
services:
app:
build:
context: c:\Users\user\project
dockerfile: .devcontainer/Django_Dockerfile
command:
- sleep
- infinity
environment:
POSTGRES_DB: postgres
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
network_mode: service:db
volumes:
- type: bind
source: c:\Users\user\project
target: /workspaces
bind:
create_host_path: true
db:
environment:
POSTGRES_DB: postgres
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
image: postgres:latest
networks:
default: null
restart: unless-stopped
volumes:
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
volume: {}
networks:
default:
name: devcontainer_default
volumes:
postgres-data:
name: devcontainer_postgres-data
[2023-01-02T13:40:03.969Z] Start: Run: docker events --format {{json .}} --filter event=start
[2023-01-02T13:40:04.315Z] PersistedPath=c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data, ContainerHasLabels=false
[2023-01-02T13:40:04.320Z] Start: Run: docker-compose -f c:\Users\user\project\.devcontainer\docker-compose.yml --profile * config
[2023-01-02T13:40:06.248Z] Stop (1928 ms): Run: docker-compose -f c:\Users\user\project\.devcontainer\docker-compose.yml --profile * config
[2023-01-02T13:40:06.248Z] name: devcontainer
services:
app:
build:
context: c:\Users\user\project
dockerfile: .devcontainer/Django_Dockerfile
command:
- sleep
- infinity
environment:
POSTGRES_DB: postgres
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
network_mode: service:db
volumes:
- type: bind
source: c:\Users\user\project
target: /workspaces
bind:
create_host_path: true
db:
environment:
POSTGRES_DB: postgres
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
image: postgres:latest
networks:
default: null
restart: unless-stopped
volumes:
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
volume: {}
networks:
default:
name: devcontainer_default
volumes:
postgres-data:
name: devcontainer_postgres-data
[2023-01-02T13:40:06.257Z] Start: Run: docker inspect --type image mcr.microsoft.com/devcontainers/anaconda:0-3
[2023-01-02T13:40:07.211Z] Stop (954 ms): Run: docker inspect --type image mcr.microsoft.com/devcontainers/anaconda:0-3
[2023-01-02T13:40:07.881Z] local container features stored at: c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\node_modules\vscode-dev-containers\container-features
[2023-01-02T13:40:07.887Z] Start: Run: tar --no-same-owner -x -f -
[2023-01-02T13:40:08.644Z] Stop (757 ms): Run: tar --no-same-owner -x -f -
[2023-01-02T13:40:08.661Z] * Processing feature: ghcr.io/devcontainers-contrib/features/angular-cli:1
[2023-01-02T13:40:09.393Z] * Fetching feature: angular-cli_1_oci
[2023-01-02T13:40:10.457Z] Start: Run: docker build -t dev_container_feature_content_temp -f C:\Users\D525C~1.SAN\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1672666807879\Dockerfile.buildContent C:\Users\D525C~1.SAN\AppData\Local\Temp\devcontainercli\container-features\0.25.2-1672666807879
[2023-01-02T13:40:11.323Z]
[2023-01-02T13:40:12.053Z]
[...]
[2023-01-02T13:41:36.506Z]
[+] Building 78.3s (7/22)
=> [internal] load build definition from Dockerfile-with-features 0.1s
=> => transferring dockerfile: 3.36kB 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/dev_container_feature_ 0.0s
=> [internal] load metadata for mcr.microsoft.com/devcontainers/anaconda 0.4s
=> [dev_containers_feature_content_source 1/1] FROM docker.io/library/de 0.0s
=> [dev_container_auto_added_stage_label 1/11] FROM mcr.microsoft.com/d 0.0s
=> ERROR [internal] load build context 77.6s
=> => transferring context: 265.86MB 77.5s
------
> [internal] load build context:
------
failed to solve: error from sender: open C:\Users\user\project\angular-14-crud-example\node_modules\make-fetch-hap
pen\node_modules\mkdirp: Accesso negato.
[2023-01-02T13:41:36.669Z] Stop (81610 ms): Run: docker-compose --project-name mydemo_devcontainer -f c:\Users\user\project\.devcontainer\docker-compose.yml -f c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data\docker-compose\docker-compose.devcontainer.build-1672666815049.yml build
[2023-01-02T13:41:36.671Z] Error: Command failed: docker-compose --project-name mydemo_devcontainer -f c:\Users\user\project\.devcontainer\docker-compose.yml -f c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data\docker-compose\docker-compose.devcontainer.build-1672666815049.yml build
[2023-01-02T13:41:36.671Z] at pF (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1850:431)
[2023-01-02T13:41:36.671Z] at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[2023-01-02T13:41:36.672Z] at async foe (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1850:2457)
[2023-01-02T13:41:36.672Z] at async loe (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1832:2396)
[2023-01-02T13:41:36.672Z] at async Poe (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1899:2301)
[2023-01-02T13:41:36.672Z] at async Zf (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:1899:3278)
[2023-01-02T13:41:36.673Z] at async aue (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:2020:15276)
[2023-01-02T13:41:36.673Z] at async oue (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js:2020:15030)
[2023-01-02T13:41:36.707Z] Stop (100459 ms): Run: C:\Users\user\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --workspace-folder c:\Users\user\project --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\Users\user\project --log-level debug --log-format json --config c:\Users\user\project\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2023-01-02T13:41:36.708Z] Exit code 1
[2023-01-02T13:41:36.716Z] Command failed: C:\Users\user\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-containers-0.266.1\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\user\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --workspace-folder c:\Users\user\project --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\Users\user\project --log-level debug --log-format json --config c:\Users\user\project\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2023-01-02T13:41:36.716Z] Exit code 1
Related
I am trying to fire up a separate redis container which will work as a broker for celery. Can someone help me with as to why the docker user is not able to open the UNIX socket. I have even tried making the user as root but it doesn't seem to work. Please find below the Dockerfile, docker-compose file and redis.conf file.
Dockerfile:
FROM centos/python-36-centos7
USER root
ENV DockerHOME=/home/django
RUN mkdir -p $DockerHOME
ENV PYTHONWRITEBYCODE 1
ENV PYTHONUNBUFFERED 1
ENV PATH=/home/django/.local/bin:$PATH
COPY ./oracle-instantclient18.3-basiclite-18.3.0.0.0-3.x86_64.rpm /home/django
COPY ./oracle-instantclient18.3-basiclite-18.3.0.0.0-3.x86_64.rpm /home/django
COPY ./oracle.conf /home/django
RUN yum install -y dnf
RUN dnf install -y libaio libaio-devel
RUN rpm -i /home/django/oracle-instantclient18.3-basiclite-18.3.0.0.0-3.x86_64.rpm && \
cp /home/django/oracle.conf /etc/ld.so.conf.d/ && \
ldconfig && \
ldconfig -p | grep client64
COPY ./requirements /home/django/requirements
WORKDIR /home/django
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r ./requirements/development.txt
COPY . .
RUN chmod 777 /home/django
EXPOSE 8000
ENTRYPOINT ["/bin/bash", "-e", "docker-entrypoint.sh"]
Docker-compose file:
version : '3.8'
services:
app:
build: .
volumes:
- .:/django
- cache:/var/run/redis
image: app_name:django
container_name: app_name
ports:
- 8000:8000
depends_on:
- db
- redis
db:
image: postgres:10.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- 5432:5432
environment:
- POSTGRES_USER=app_name
- POSTGRES_PASSWORD=app_password
- POSTGRES_DB=app_db
labels:
description : "Postgres Database"
container_name: app_name-db-1
redis:
image: redis:alpine
command: redis-server /etc/redis/redis.conf
restart: unless-stopped
ports:
- 6379:6379
volumes:
- ./redis/data:/var/lib/redis
- ./redis/redis-server.log:/var/log/redis/redis-server.log
- cache:/var/run/redis/
- ./redis/redis.conf:/etc/redis/redis.conf
container_name: redis
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 30
volumes:
postgres_data:
cache:
static-volume:
docker-entrypoint.sh:
# run migration first
python manage.py migrate
python manage.py preload_sites -uvasas -l
python manage.py preload_endpoints -uvasas -l
python manage.py collectstatic --noinput
#start celery
export C_FORCE_ROOT='true'
celery multi start 1 -A realm -l INFO -c4
# start the server
python manage.py runserver 0:8000
redis.conf
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
logfile /var/log/redis/redis-server.log
I am new to docker so apologies if I have not done something very obvious or if I have not followed some of the best practices.
I have configurated the next compose.yml
version: "3.9"
x-aws-cluster: cluster
x-aws-vpc: vpc-A
x-aws-loadbalancer: balancerB
services:
backend:
image: backend:1.0
build:
context: ./backend
dockerfile: ./dockerfile
command: >
sh -c "python manage.py makemigrations &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8002"
networks:
- default
- allowedips
ports:
- "8002:8002"
frontend:
tty: true
image: frontend:1.0
build:
context: ./frontend
dockerfile: ./dockerfile
command: >
sh -c "npm i --save-dev vue-loader-v16
npm install
npm run serve"
ports:
- "8080:8080"
networks:
- default
- allowedips
depends_on:
- backend
networks:
default:
external: true
name: sg-1
allowedips:
external: true
name: sg-2
I thought it like:
sg-1: Default security group
sg-2: Allowed IPs access
If I run
docker compose up -d
it runs well without any problem and I can use the app.
My dude is that the process create
Allowedips8002Ingress
Allowedips8080Ingress
Default8002Ingress
Default8080Ingress
I don't want this, I will have a allowed IPs inbound rules in sg-2. How can I avoid this?
I'm trying to make sure my Django app waits for my Postgres db to start so I don't get this error django.db.utils.OperationalError: FATAL: the database system is starting up, I've read this https://docs.docker.com/compose/startup-order/, and here is what I have so far
docker-compose.yml
version: "3.9"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
backend:
build: ./backend
command: python3 manage.py runserver
volumes:
- ./backend:/code
ports:
- "8000:8000"
command: ["./wait-for-it.sh", "db", "bash", "entrypoint.sh"]
depends_on:
- db
wait-for-it.sh
#!/bin/sh
# wait-for-it.sh
set -e
host="$1"
shift
cmd="$#"
# postgres
until PGPASSWORD=$DB_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd
Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.9.6-alpine3.14
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps
COPY . /code/
RUN chmod u+x ./wait-for-it.sh
EDIT #1:
This is my directory structure
Root directory
Backend directory
You are trying to combine several different solutions.
First of all, if you use pg_isready, you don't need any custom wait-for-it.sh scripts because pg_isready works great. So just remove your wait-for-it.sh file.
Also if you use healthcheck in the docker-compose.yml, you don't need to run any check scripts manually before running your entrypoint.sh. But you need to add condition to depends_on section. So change your docker-compose.yml to the following:
version: "3.9"
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
interval: 5s
timeout: 5s
retries: 5
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
backend:
build: ./backend
volumes:
- ./backend:/code
ports:
- "8000:8000"
command: entrypoint.sh
depends_on:
db:
condition: service_healthy
Be aware, I also changed test command in healthcheck section and removed first command in backend image.
I don't achieve to communicate with my database postgres using Docker and Django. Here is my docker-compose.yml :
version: '3'
services:
web:
container_name: web
build:
context: ./web
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./web/:/usr/src/web/
ports:
- 8000:8000
- 3000:3000
- 35729:35729
env_file:
- database.env
stdin_open: true
depends_on:
- database
database:
container_name: database
image: postgres
volumes:
- database-data:/var/lib/postgresql/data/
ports:
- 5432:5432
volumes:
database-data:
Here is my database.env :
# database.env
POSTGRES_USERNAME=admin
POSTGRES_PASSWORD=pass
POSTGRES_DBNAME=db
POSTGRES_HOST=database
POSTGRES_PORT=5432
PGUSER=admin
PGPASSWORD=pass
PGDATABASE=db
PGHOST=database
PGPORT=5432
DATABASE=db
SQL_HOST=database
SQL_PORT=5432
And here is my Dockerfile :
# pull official base image
FROM python:3.8.3-alpine
# set work directory
WORKDIR /usr/src/web
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
RUN apk add zlib-dev jpeg-dev gcc musl-dev
# install nodejs
RUN apk add --update nodejs nodejs-npm
# copy project
ADD . .
# install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
# run entrypoint.sh
ENTRYPOINT ["sh", "/usr/src/web/entrypoint.sh"]
And there my entrypoint.sh :
#!/bin/sh
if [ "$DATABASE" = "db" ]
then
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 10
done
echo "PostgreSQL started"
fi
exec "$#"
I build the docker using that : docker-compose up -d --build
Then I type that : docker-composexec web npm start --prefix ./front/ .
I can access to the frontent : http://localhost:3000
But when I do docker logs database I got that :
2021-01-18 06:31:49.207 UTC [1] LOG: database system is ready to accept connections
2021-01-18 06:31:51.640 UTC [32] FATAL: password authentication failed for user "admin"
2021-01-18 06:31:51.640 UTC [32] DETAIL: Role "admin" does not exist.
Connection matched pg_hba.conf line 99: "host all all all md5"
Here is the status :
37ee3e314d52 web "sh /usr/src/web/ent…" About a minute ago Up About a minute 0.0.0.0:3000->3000/tcp, 0.0.0.0:8000->8000/tcp, 5432/tcp web
65dfeae57a94 postgres "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp database
Coud you help me ?
Thank you very much !
It seems like the postgres user you are using doesn't exist. You can add some environment variables to database docker-compose to create those (you probably need to create the database, too), Or you can write some script to create those for the first time.
version: '3'
services:
web:
container_name: web
build:
context: ./web
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./web/:/usr/src/web/
ports:
- 8000:8000
- 3000:3000
- 35729:35729
env_file:
- database.env
stdin_open: true
depends_on:
- database
database:
container_name: database
image: postgres
volumes:
- database-data:/var/lib/postgresql/data/
ports:
- 5432:5432
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=db
volumes:
database-data:
About postgres image envs you can check this link .
Title says for itself. Everything works perfectly, except tests. After pulling and running test(test stage) service, it says Ran 0 tests in 0.000s, but i have some basic tests and they run perfectly on my system. Just can't quite figure out what is wrong.
I have a docker-compose file like this:
version: '2'
services:
postgres:
image: "postgres"
ports:
- 5432:5432
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=solo
- POSTGRES_DB=solo
- POSTGRES_PASSWORD=solo
- POSTGRES_HOST_AUTH_METHOD=trust
web:
image: $CI_REGISTRY:$CI_COMMIT_REF_NAME
build: .
environment:
- SECRET_KEY
command: bash -c "cd src && gunicorn solo.wsgi:application --bind 0.0.0.0:8000"
volumes:
- static:/app/static
expose:
- 8000
depends_on:
- postgres
restart: always
test:
image: $CI_REGISTRY:$CI_COMMIT_REF_NAME
command: bash -c "python /app/src/manage.py test"
depends_on:
- postgres
nginx:
build: ./nginx
volumes:
- static:/app/static
ports:
- 80:80
depends_on:
- web
volumes:
static:
postgres_data:
And .gitlab-ci.yml like this:
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- deploy
before_script:
- apk add --no-cache py-pip
- pip install docker-compose==1.9.0
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
build:
stage: build
script:
- docker-compose build
- docker-compose push
test:
stage: test
script:
- docker-compose pull test
- docker-compose run test
deploy:
stage: deploy
only:
- master
- cicddev
before_script:
- apk add --update alpine-sdk
- apk add python3-dev libffi-dev libffi-dev libressl-dev
- apk add --no-cache openssh-client py-pip bash rsync
- pip install Fabric3==1.14.post1
- eval $(ssh-agent -s)
- bash -c 'echo "${DEPLOY_KEY}" | ssh-add -'
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
- fab -H ${DEPLOY_ADDRESS} deploy
Any thoughts or suggestions?
Found solution here Django test runner not finding tests.
Django won't find test if you're trying to call test from parent folders. So I had to change command: bash -c "python /app/src/manage.py test" to command: bash -c "cd src && python manage.py test"