I am working on MS Blazor server two projects solution (Core 6) and GitLab.
docker-compose.yml file:
version: '3.4'
services:
admin:
image: ${DOCKER_REGISTRY-}admin
build:
context: .
dockerfile: FrontEnd/Admin/Dockerfile
enrollment:
image: ${DOCKER_REGISTRY-}enrollment
build:
context: .
dockerfile: FrontEnd/Enrollment/Dockerfile
GitLab pipeline file:
image: docker:stable
services:
- docker:dind
before_script:
- docker info
build:
only:
- DockerComposeSupported
before_script:
- docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
script:
- apk add --no-cache docker-compose
- docker-compose build #Works fine
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH} # Here is the error
after_script:
- docker logout ${CI_REGISTRY}
stage: build
The problem is in line: - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}, the error is
The push refers to repository [registry.gitlab.com/xxx/yyy/zzz]
An image does not exist locally with the tag: registry.gitlab.com/xxx/yyy/zzz
I originally grab the code from Gitlab, it was
docker build -t registry.gitlab.com/xxx/yyy/zzz .
But the docker build is looking for a docker file in the root directory and I do not have one, I have docker-compose only so I need to use the "docker-compose build" but this command does not have any directory parameter.
Any help will be greatly appreciated.
Use a different variable defined by GitLab in CI: CI_REGISTRY_IMAGE="registry.example.com/org/repo"
version: '3.4'
services:
admin:
image: ${CI_REGISTRY_IMAGE}-admin
build:
context: .
dockerfile: FrontEnd/Admin/Dockerfile
enrollment:
image: ${CI_REGISTRY_IMAGE}-enrollment
build:
context: .
dockerfile: FrontEnd/Enrollment/Dockerfile
docker-compose has a nifty feature where you can set this variable in a .env file within the same directory as the docker-compose.yml file. You will only need this file for local development.
# .env
CI_REGISTRY_IMAGE="registry.example.com/org/repo"
GitLab Docs: Predefined variables
Docker Docs: The .env file
Thanks, Richard and Danielnelz! I've found a solution for the "requested access to the resource is denied" error. I had "{CI_REGISTRY_IMAGE}-admin" project reference but it should be {CI_REGISTRY_IMAGE}/admin. Now the docker push to the GitLab registry is working fine.
Related
for example, my project directory is
project/
- docker-compose.yml
- Dockerfile
docker-compose.yml is
services:
app1:
build:
context: .
target: development
dockerfile: Dockerfile
so if i run
docker-compose -f docker-compose.yml build app1
will generate an image project_app, but if i run
docker-compose build
the image name will be project-app.
my question is why is this happening and if there is any way to persist the name without changing docker-compose.yml?
docker-compose version 1.29.2
In Github Actions I want to test my frontend through Cypress. I run my Jekyll application in a Docker container and then run the tests in the next step. However, when connecting the Cypress tests to the Docker container I get a 'Connection refused' error. Does anyone know how I can access my container after running docker-compose?
This is my Github Actions yml file:
name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Cypress run
uses: cypress-io/github-action#v4.2.0
with:
start: docker-compose up -d
This is my docker-compose file:
version: '2'
services:
jekyll:
image: jekyll/jekyll:latest
command: jekyll serve --watch --force_polling --verbose
ports:
- 4000:4000
volumes:
- .:/srv/jekyll
So apparently although my Jekyll container started perfectly fine, the actual Jekyll server crashed on startup. I needed to specify the UID and GID of Github actions to my Jekyll environment in order for it to start correctly.
This is my new docker-compose file:
version: '2'
services:
jekyll:
image: jekyll/jekyll:latest
command: jekyll serve --watch --force_polling --verbose
hostname: localhost
environment:
JEKYLL_UID: 1001
JEKYLL_GID: 1001
ports:
- 4000:4000
volumes:
- .:/srv/jekyll
I have a docker-compose file to run cypress tests, but I see that it is identifying all the spec files in the integration folder and running the tests. I wanted to run a subset of the spec files . for example: only one specific spec file.
I tried with command: and the cypress run the specific file which did not help. Is there any way to run a specific spec file with the docker-compose setup.
version: '3.2'
services:
cypress:
image: 'cypress/included:6.6.0'
environment:
- CYPRESS_environment=test
working_dir: /test
volumes:
- ./:/test
If you look at the Dockerfile it uses entrypoint, so you can use a command parameter in your compose file to run specific file
version: '3.2'
services:
cypress:
image: 'cypress/included:6.6.0'
environment:
- CYPRESS_environment=test
working_dir: /test
volumes:
- ./:/test
command: "--spec /test/integration/mytest.js"
I am trying to deploy a Flack app/service which is built into a docker container to Gitlab CI. I am able to get everything working via docker-compose except when I try to run tests against the postgres database I am getting the below error:
Is the server running on host "events_db" (172.19.0.2) and accepting
TCP/IP connections on port 5432?
Presumably this is because the containers can't see each other. I've tried many different methods. But below is my latest. I have attempted to have docker-compose spin up both containers (just like it does on local), run the postgres db as a git lab service, run from a python image instead of a docker image, use a docker.prod.yml where I remove the volumes and variables.
Nothing is working. I've checked just about every link that shows up on google when you look for 'gitlab ci docker flask postgres' and I believe that I am massively misunderstanding the implementation.
I do have gitlab runner up and going.
.gitlab-ci.yml
image: docker:latest
services:
- docker:dind
- postgres:latest
stages:
- test
variables:
POSTGRES_DB: events_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
DATABASE_URL: postgres://postgres#postgres:5432/events_test
FLASK_ENV: development
APP_SETTINGS: app.config.TestingConfig
DOCKER_COMPOSE_VERSION: 1.23.2
before_script:
#- rm /usr/local/bin/docker-compose
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
#- mv docker-compose /usr/local/bin
- docker-compose up -d --build
test:
stage: test
#coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
script:
- docker-compose exec -T events python manage.py test
after_script:
- docker-compose down
docker-compose.yml
version: '3.3'
services:
events:
build:
context: ./services/events
dockerfile: Dockerfile
volumes:
- './services/events:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=app.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres#events_db:5432/events_dev # new
- DATABASE_TEST_URL=postgres://postgres:postgres#events_db:5432/events_test # new
events_db:
build:
context: ./services/events/app/db
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
What is the executor type of your Gitlab Runner?
If you're using the Kubernetes executor, add this variable:
DOCKER_HOST: tcp://localhost:2375/
For non-Kubernetes executors, we use tcp://docker:2375/
DOCKER_HOST: tcp://docker:2375/
Also, the Gitlab Runner should be in "privileged" mode.
More info:
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#help-and-feedback
Hope that helps!
I'm new to docker.
Here is my simple docker-compose file.
version: '3.4'
services:
web:
image: 'myimage:latest'
build: .
ports:
- "5265:5265"
environment:
- NODE_ENV=production
To run this, I usually use docker-compose up command.
Can I change the NODE_ENV variable to anything while running docker-compose up?
For example:
docker-compose up -x NODE_ENV=staging
Use docker-compose run, you can manage services but not the complete stack. Useful for one-off commands.
$ docker-compose run -d -e NODE_ENV=staging web
Ref - https://docs.docker.com/compose/reference/run/
OR
Best way i could see as if now is to use shell & export the environment variable before doing a docker-compose up as below -
$ export NODE_ENV=staging && docker-compose up -d
Where your docker-compose will look something as below -
version: '3.4'
services:
web:
image: 'myimage:latest'
build: .
ports:
- "5265:5265"
environment:
- NODE_ENV=${NODE_ENV}