docker : No subsytem for mount - docker

I'm running a CI pipeline in gitlab-runner which is running on a linux machine.
In the pipeline I'm trying to build an image.
The Error I'm getting is,
ci runtime error: rootfs_linux.go:53: mounting "/sys/fs/cgroup" to rootfs "/var/lib/docker/overlay/d6b9ba61e6eed4bcd9c23722ad6f6a9fb05b6c536dbab31f47b835c25c0a343b/merged" caused "no subsystem for mount"
The Dockerfile contains :
# Set the base image to node:12-alpine
FROM node:16.7.0-buster
# Specify where our app will live in the container
WORKDIR /app
# Copy the React App to the container
COPY . /app/
# Prepare the container for building React
RUN npm install
RUN npm install react-scripts#4.0.3 -g
# We want the production version
RUN npm run build
# Prepare nginx
FROM nginx:stable
COPY --from=0 /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
# Fire up nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The gitlab-ci.yml contains :
image: gitlab/dind
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build
- docker-build
cache:
paths:
- node_modules
yarn-build:
stage: build
image: node:latest
script:
- unset CI
- yarn install
- yarn build
artifacts:
expire_in: 1 hour # the artifacts expire from the artifacts folder after 1 hour
paths:
- build
docker-build:
stage: docker-build
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker build -t $CI_REGISTRY_USER/$app_name .
- docker push $CI_REGISTRY_USER/$app_name
I'm not getting how to resolve this, I tried upgrading docker in my linux machine.

Related

Gitlab CI hangs on npm run build (webpack production command)

GitLab Pipeline Output
GitLab CI/CD YML file
image: docker:latest
services:
- docker:dind
stages:
- test
test_stage:
stage: test
tags:
- def
before_script:
- apk version
- apk add --no-cache docker-compose
- docker info
- docker-compose --version
script:
- echo "Building and testing"
- docker-compose up --abort-on-container-exit
Dockerfile
FROM node:10.15.3 as source
COPY package.json ./
COPY package-lock.json ./
RUN node -v
RUN npm -v
RUN npm install
COPY . ./
RUN npm run build
FROM nginx:1.15.9
COPY default.template /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
'npm run build' from the Dockerfile runs 'webpack --mode production' which attempts to start my app on localhost within Docker. Instead, GitLab is getting stuck in 'npm run build'.
This works locally with Docker but not on the GitLab CI/CD runner, it seems to be hanging there and potentially having an out of memory error, which I received earlier when it was hanging even longer.
Why is the GitLab runner getting stuck on 'webpack --mode production' (my npm run build command)? Should I only be using 'webpack -p"?

Gitlab job failed when I try to build Docker image

There is the following Dockerfile:
FROM node:12.22-alpine3.12 as builder
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN npm i && npm build
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
EXPOSE 80
COPY --from=builder /app/build ./
ENTRYPOINT ["nginx", "-g", "daemon off;"]
There is nothing smart - just build static JS app and put it to nginx directory. It works locally excellent. But it failed on Gitlab with the following error:
Step 8/11 : RUN rm -rf ./*
---> Running in a9cf55a3da31
Removing intermediate container a9cf55a3da31
---> 50c9a02d542d
Step 9/11 : EXPOSE 80
---> Running in edda7f7bf296
Removing intermediate container edda7f7bf296
---> be2caf89404f
Step 10/11 : COPY --from=builder /app/build ./
COPY failed: stat /var/lib/docker/overlay2/6a441679247bd4e1a321f7c6e15d4fe8dd59c5013d4e0058b7f3c9f395c20f98/merged/app/build: no such file or directory
Cleaning up file based variables
00:02
ERROR: Job failed: command terminated with exit code 1
And I don't understand what does it mean, because locally it works without any troubles at all.
UPD: my .gitlab-ci.yml:
stages:
- test
- build
test:
stage: test
image: node:12.22-alpine3.12
script:
- echo 'Test Success'
build:
image: docker:19.03.12
stage: build
services:
- docker:19.03.12-dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID"

Docker Build Failing on Travis --> can't find app/build

I am trying to push my images from Travis CI to docker hub.
Here is my Dockerfile
FROM node:alpine as builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
CMD npm run build
FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
My .travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t aseel/react-test -f ./client/Dockerfile.dev ./client
script:
- docker run -e CI=true aseel/react-test npm run test
after_success:
- docker build -t aseel/multi-client ./client
- docker build -t aseel/multi-nginx ./nginx
- docker build -t aseel/multi-server ./server
- docker build -t aseel/multi-worker ./worker
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push aseel/multi-server
- docker push aseel/multi-nginx
- docker push aseel/multi-worker
- docker push aseel/multi-client
The reason the push is failing is because this command
docker build -t aseel/multi-client ./client
is failing on travis (but not locally).
More specifically, I'm getting this error on travis
COPY failed: stat
/var/lib/docker/overlay2/135282513e177be132b6978986f878ba61f3b89914b6b2f7030cbafa0d33f629/merged/app/build:
no such file or directory
Any idea why this is happening?
I needed to switch CMD to RUN -- It was a pretty silly mistake

Docker Compose task in VSTS : Couldn't connect to Docker daemon at http+docker://localhost - is it running?

Installed docker 18.03 on vsts agent box(self-hosted VSTS agent)
The user under which the agent is running has been added to the docker group.
When I try to build using Docker Compose task in VSTS, the build fails with error:
Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
/usr/local/bin/docker-compose failed with return code: 1
I have been stuck in this for few hours, any help will be awesome.
One more note: docker compose works perfectly fine from the agent box, but when the build is triggered by VSTS task I get this error.
docker-compose file:
version: '3'
services:
some-api:
build:
context: .
dockerfile: .docker/dockerfile1
image: some.azurecr.io/some-api:latest
container_name: 'some-api'
ports:
- '8080:80'
some-website:
build:
context: .
dockerfile: .docker/dockerfile2
image: some.azurecr.io/some-website:latest
container_name: 'some-website'
ports:
- '3434:3434'
dockerfile -api
FROM microsoft/dotnet AS build
# Docker image container .NET Core SDK
COPY .api/ ./some-api
WORKDIR /some-api
RUN dotnet restore; dotnet publish -o out
# final image
FROM microsoft/aspnetcore
# .NET Core runtime-only image
COPY --from=build /some-api/out /some-api
WORKDIR /some-api
EXPOSE 80
ENTRYPOINT [ "dotnet", "some.dll" ]
dockerfile-website
#----------------------
### STAGE 1: BUILD ###
#---------------------
# Building node from LTS version
FROM node:8.11.1 as builder
# Installing npm to remove warnings and optimize the container build process
# One of many warnings: npm WARN notice [SECURITY] deep-extend has 1 low vulnerability.
#Go here for more details: https://nodesecurity.io/advisories?search=deep-extend&version=0.5.0 -
#Run `npm i npm#latest -g` to upgrade your npm version, and then `npm audit` to get more info.
RUN npm install npm#latest -g
# Copying all necessary files required for npm install
COPY package.json ./
# Install npm dependencies in a different folder to optimize container build process
RUN npm install
# Create application directory and copy node modules to it
RUN mkdir /some-website
RUN cp -R ./node_modules ./some-website
# Setting application directory as work directory
WORKDIR /some-website
# Copying application code to container application directory
COPY . .
# Building the angular app
RUN npm run build.prod
#--------------------------------------------------
### STAGE 2: Setup nginx and Deploy application ###
#--------------------------------------------------
FROM nginx:latest
## Copy defualt ngninx configuration file
COPY default.conf /etc/nginx/conf.d
## Remove default nginx website
RUN rm -rf /usr/share/nginx/hmtl/*
# Copy dist folder from the builder to nginx public folder(STAGE 1)
COPY --from=builder /some-website/dist/prod /usr/share/nginx/html
CMD ["nginx","-g","daemon off;"]
Thanks
The issue was user permissions. So after adding a user to the docker group,
sudo usermod -aG docker $USER
logging out and logging in didn't work. I had to reboot my ubuntu server in order for permissions to take effect.

Docker images using circleci

I am working on integrating CI/CD pipeline using Docker. How can i use dockercompose file to build and create container?
I have tried it in putting Dockerfile, and docker-compose.yml, but none of them works.
Below is docker-compose file :
FROM ruby:2.2
EXPOSE 8000
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN bundle install
CMD ["ruby","app.rb"]
RUN docker build -t itsruby:itsruby .
RUN docker run -d itsruby:itsruby
Below is docker-compose.yml
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
- run: |
docker build -t itsruby:itsruby .
docker run -d itsruby:itsruby
test:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
The build is getting failed in circle/ci.

Resources