I am trying to set up a GitLab CI/CD pipeline with this following .gitlab-ci.yml file:
stages:
- test
image: "ros:foxy-ros-base-focal"
before_script:
- apt-get -y update && apt-get install -y \
git wget qt5-default \
python3-osrf-pycommon \
python3-catkin-tools \
python3-rosdep \
python3-vcstool \
python3-pip \
python3-colcon-common-extensions \
apt-utils
- rm -rf /var/lib/apt/lists/*
- /bin/bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash; colcon build"
- echo "source /root/dev_ws/install/setup.bash" >> /opt/ros/${ROS_DISTRO}/setup.bash
test_a:
stage: test
script:
- pip3 install pytest
- python -m pytest test_utils.py -vv -s
I am starting from the ROS2 Foxy Base Focal Docker image. However, despite running apt-get update, I still can't find many of the packages, including git as well as several other ROS2 packages. Full log here:
Running with gitlab-runner 13.8.0 (775dd39d)
on docker-auto-scale fa6cab46
Preparing the "docker+machine" executor
00:27
Using Docker executor with image ros:foxy-ros-base-focal ...
Pulling docker image ros:foxy-ros-base-focal ...
Using docker image sha256:59cf2af10ce4181bf4effbc683375f5e201bfe072c808c75fb3ee903b98265b9 for ros:foxy-ros-base-focal with digest ros#sha256:4f924ff4fdee6b7c999ad6bc013741bdf8430466c7a27842ac6255255ce9ae66 ...
Preparing environment
00:02
Running on runner-fa6cab46-project-23977848-concurrent-0 via runner-fa6cab46-srm-1611897044-53c1946d...
Getting source from Git repository
00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/imda_dsl/vama-2/scene-understanding/scene-understanding-manager/.git/
Created fresh repository.
Checking out fc385931 as dev...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:05
$ apt-get -y update && apt-get install -y \ git wget qt5-default \ python3-osrf-pycommon \ python3-catkin-tools \ python3-rosdep \ python3-vcstool \ python3-pip \ python3-colcon-common-extensions \ apt-utils
Get:1 http://packages.ros.org/ros2/ubuntu focal InRelease [4670 B]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:4 http://packages.ros.org/ros2/ubuntu focal/main amd64 Packages [451 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [161 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [598 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [659 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [13.3 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1003 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [21.1 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [194 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [920 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [4301 B]
Fetched 17.4 MB in 2s (7001 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package git
E: Unable to locate package python3-osrf-pycommon
E: Unable to locate package python3-catkin-tools
E: Unable to locate package python3-rosdep
E: Unable to locate package python3-vcstool
E: Unable to locate package python3-pip
E: Unable to locate package python3-colcon-common-extensions
E: Unable to locate package apt-utils
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
Installing packages or even running update commands in your .gitlab-ci.yml is generally against best practices for a CI/CD container because each and every job that runs will have to do the same thing, costing a lot of time as you run more pipelines. If you can't find an existing Docker image that has the packages you need (so as an example, python3 and git), you can create your own images. If you need to extend the image from your job, ros:foxy-ros-base-focal, create a Dockerfile file with the following contents:
FROM ros:foxy-ros-base-focal
MAINTAINER your name "your email"
RUN apt-get update -yqq
RUN apt-get install -yqq git
You can install/configure whatever else you need to do in there too, then when you're done build the image:
docker build /path/to/dir-with-dockerfile -t tagname:version
Once the build is done you can verify the tag is correct with docker images, then you can push it to a registry (docker hub, gitlab's registry if enabled, private registry, etc) with:
docker login my.hub.example.com
docker push my.hub.example.com/tagname:version
Then in your .gitlab-ci.yml file, you can use the tagname:version image in your jobs:
stages:
- test
image: "tagname:version"
...
If you have to auth to use your registry, you'll have to review the docs here https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-an-image-from-a-private-container-registry, and the general docs for using docker images in your pipelines is here: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html
Related
Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last month.
The community reviewed whether to reopen this question last month and left it closed:
Original close reason(s) were not resolved
Improve this question
I currently don't manage to run apt update inside a fresh ubuntu:22.04 (codename jammy).
Protocol
$ docker --version
Docker version 20.10.2, build 2291f61
$ docker run --init --rm -it ubuntu:22.04
root#123456789:/# apt update
Observed
$ docker run --init --rm -it ubuntu:22.04
root#6444bf2cb8b4:/# apt update
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [90.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [90.7 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [90.7 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Fetched 20.2 MB in 1s (17.6 MB/s)
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true'
E: Sub-process returned an error code
root#6444bf2cb8b4:/#
Expected
apt update pass like on a ubuntu:20.04 base image...
note: same issue with apt-get install ...
ref: https://hub.docker.com/_/ubuntu
Seems this is related to the use of the syscall clone3 by Glibc >= 2.34...
So you need Docker >= 20.10.9 to fix it.
ref: https://github.com/moby/moby/pull/42681
ref: https://pascalroeleven.nl/2021/09/09/ubuntu-21-10-and-fedora-35-in-docker/
I ran into the same issue. Here is my tactical work-around.
For context ...
I am working inside a Gitpod instance.
$ docker --version
Docker version 20.10.12, build e91ed57
$ docker pull ubuntu:22.04
$ docker run --rm -it ubuntu:22.04 /bin/bash
root#2fcf92fb7c84:/# apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [90.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [90.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [90.7 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Fetched 20.2 MB in 2s (11.1 MB/s)
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true'
E: Sub-process returned an error code
Quick nano install ...
Despite the error message above, the update was sufficient to install nano. I ignore the misleading error message at the end of the nano install.
root#3958950e9c57:/# apt install nano
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
:
E: Problem executing scripts DPkg::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true'
E: Sub-process returned an error code
My fix ...
I use nano to edit /etc/apt/apt.conf.d/docker-clean, commenting out the second line (APT::...). I subsequently ran into a similar error message with line 1 (DPkg::...); so, it too gets commented out.
It might be okay to just remove docker-clean all together; but for now, I have left one line in place.
Both '//' and '#' can be used to comment out lines.
root#3958950e9c57:/# nano /etc/apt/apt.conf.d/docker-clean
.. nano session not shown ..
root#3958950e9c57:/# cat /etc/apt/apt.conf.d/docker-clean
# DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
# APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";
The results ...
The confusing message resulting from the now commented-out lines is gone.
root#beab61fbde20:/# apt update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Required Improvement ...
A better solution would be to repair the line that I have commented out. I was not able to find the right edits; so, just left the line commented out.
In Docker ...
I use sed in lieu of nano.
FROM ubuntu:22.04
USER root
RUN sed -i -e 's/^APT/# APT/' -e 's/^DPkg/# DPkg/' \
/etc/apt/apt.conf.d/docker-clean
Then, tag an adjusted Ubuntu image for local use.
docker build -t fixed-ubuntu:22.04 -f Dockerfile .
I upgraded docker engine to version 20.10.14 and it resolved the problem.
I had docker 20.10.18 (latest at time writing) which didn't work, with 20.10.14 it started to work.
I am trying to create a Docker image of Cassandra. Cassandra requires Java. I have added line to install java. In my Docker file
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install default-jre
COPY apache-cassandra-3.11.6-bin.tar.gz .
RUN tar -xzf apache-cassandra-3.11.6-bin.tar.gz
RUN chmod -R 777 apache-cassandra-3.11.6
RUN ls
RUN echo $PATH
RUN echo $PWD
RUN apt update
#RUN apt-get install openjdk-7-jdk
#RUN java -version
WORKDIR apache-cassandra-3.11.6
RUN ls
ENV CASSANDRA_HOME=/apache-cassandra-3.11.6
ENV PATH=$PATH:$CASSANDRA_HOME/bin
RUN echo $PATH
RUN ls
WORKDIR apache-cassandra-3.11.6/bin
RUN ls
CMD ["cassandra","-f"]
I am getting error in apt-get update and apt. How can I fix this?
C:\Users\manuc\Documents\manu\cassandra_image_test>docker build -f CassandraImageDockerFile.txt -t manucassandra .
Sending build context to Docker daemon 184.8MB
Step 1/19 : FROM ubuntu:20.04
---> 74435f89ab78
Step 2/19 : RUN apt-get update
---> Running in b395852c8e6b
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [107 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Reading package lists...
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 1d 13h 27min 45s). Updates for this repository will not be applied.
E: Release file for http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 1d 12h 39min 24s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 1d 12h 39min 54s). Updates for this repository will not be applied.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
This seems to be an issue with your timezone. Please restart your Docker host.
Docker Desktop:
You can manually restart it using UI.
Docker machine:
$ docker-machine restart <DOCKER-MACHINE-NAME>
Podman:
$ podman restart <PODMAN-MACHINE-NAME>
I want to build a docker image based on php:5.6.32-apache.
The content involved in this within my Dockerfile is:
FROM php:5.6.32-apache
....
RUN apt-get update -y
The console output from the built process is:
Step 6/10 : RUN apt-get update -y
---> Running in 8781a7a005ad
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [7340 B]
Get:3 http://deb.debian.org jessie Release.gpg [2420 B]
Get:4 http://deb.debian.org jessie Release [148 kB]
Get:5 http://security.debian.org jessie/updates/main amd64 Packages [846 kB]
Get:6 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/InRelease Unable to find expected entry 'main/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)
E: Some index files failed to download. They have been ignored, or old ones used instead.
Fetched 10.1 MB in 17s (565 kB/s)
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get update -y' returned a non-zero code: 100
You can find the original php:5.6.32-apache Dockerfile here:
https://github.com/docker-library/php/blob/ec6b6e60b42c283d48775596f722f5250c1f5ca5/5.6/jessie/apache/Dockerfile
Duplicate. Please find solution at:
Build Error. Failed to fetch Build Error. Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages
When I run docker on local machine with following Dockerfile:
FROM python:3
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get install -y libhunspell-1.3-0
RUN pip install -r requirements.txt
EXPOSE 9876
CMD ["python","flask_compose.py"]
It got libhunspell from following repository (jessie):
Get:1 http://security.debian.org jessie/updates InRelease [94.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [623 kB]
Get:4 http://deb.debian.org jessie Release.gpg [2434 B]
Get:5 http://deb.debian.org jessie Release [148 kB]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9064 kB]
And everything is fine (image build and run successfully).
Unfortunately, when I run docker on gitlab repository with the same Dockerfile it calls update apt-get from another repository (stretch):
Ign:1 http://deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:3 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:4 http://deb.debian.org/debian stretch Release [118 kB]
Get:5 http://deb.debian.org/debian stretch Release.gpg [2434 B]
Get:6 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [440 kB]
Get:7 http://deb.debian.org/debian stretch-updates/main amd64 Packages [12.1 kB]
Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [9530 kB]
Due to this inconsistency gitlab CI/CD throws following exception:
E: Unable to locate package libhunspell-1.3-0
E: Couldn't find any package by glob 'libhunspell-1.3-0'
E: Couldn't find any package by regex 'libhunspell-1.3-0'
The command '/bin/sh -c apt-get install -y libhunspell-1.3-0' returned a non-zero code: 100
ERROR: Job failed: exit code 100
Does anyone knows how change my Dockerfile that local and gitlab uses the same package repository?
There current tag for python:3 points to a Debian stretch based image. To update your local environment, run a docker pull python:3 or run your build with the --pull option.
You can also select a more specific tag to force your desired base image used by python. See the docker hub page for python to see all the possible tags, e.g. python:3-jessie.
From gitlab official forum I found a solution which fixed my problem.
1) define a setup.sh file and following command:
echo "deb http://pkg.adfinis-sygroup.ch/debian/ jessie main non-free contrib" > /etc/apt/sources.list
echo "deb http://security.debian.org/ jessie/updates main" >> /etc/apt/sources.list
echo "deb http://pkg.adfinis-sygroup.ch/debian/ jessie-updates main contrib non-free" >> /etc/apt/sources.list
apt-get update
apt-get install --no-install-recommends -y libhunspell-1.3-0
2) In Dockerfile add following commands:
From python:3
ADD setup.sh /opt/
RUN /bin/bash /opt/setup.sh
PS: Although my hack works very fine, I prefer #BMitch solution.
--------------------------------------------------------------------------------------------------------
By extending #Bmitch solution I decrease image size from ~600 to ~150 with following Dockerfile:
FROM python:3-slim-jessie
WORKDIR .
# hunspell deps
RUN apt-get update && apt-get install --no-install-recommends -y libtool libc6-dev gcc g++ build-essential libhunspell-1.3-0
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python","flask_compose.py"]
I am using CircleCI to run tests and deploy a Docker image, but I'm having trouble caching Docker images, leading to very long build times.
Here's a minimal example that does not work:
circle.yml
machine:
services:
- docker
dependencies:
cache_directories:
- "~/docker"
override:
- if [[ -e ~/docker/image.tar ]]; then echo "cached files exists!" ; docker load -i ~/docker/image.tar; fi
- docker images
- docker build -t myorg/myapp:v1.1.1 .
- mkdir -p ~/docker; docker save myorg/myapp:v1.1.1 > ~/docker/image.tar
Dockerfile:
FROM debian:latest
MAINTAINER My Name <myname#gmail.com>
RUN apt-get update && apt-get install -y vim
CMD ["sleep", "3"]
When pushing to GitHub, the build runs fine in CircleCI. But the Docker image is rebuilt every time it runs. This gets very time consuming in a production Docker image.
The file image.tar is clearly loaded, which is clear from the output of the docker images command, but it still builds the total image every time, even when the Dockerfile does not change.
Here's some of the output from the line docker build -t myorg/myapp:v1.1.1 .
docker build -t myorg/myapp:v1.1.1 .
Sending build context to Docker daemon 67.07 kB
Step 1 : FROM debian:latest
latest: Pulling from library/debian
Digest: sha256:370807fef6f790d8519399026d26461bdf8360f94ab450da94c2350bea3cc66d
Status: Downloaded newer image for debian:latest
---> ae85c48b369c
Step 2 : MAINTAINER My Name <myname#gmail.com>
---> Running in 4ffd69c2a82d
---> 6029750ba0f3
Error removing intermediate container 4ffd69c2a82d: rmdriverfs: Driver btrfs failed to remove root filesystem 4ffd69c2a82d644ea7ee8576cc06e67ee412f651edecbc40932394c057aa931d: Failed to destroy btrfs snapshot /var/lib/docker/btrfs/subvolumes for 4ffd69c2a82d644ea7ee8576cc06e67ee412f651edecbc40932394c057aa931d: operation not permitted
Step 3 : RUN apt-get update && apt-get install -y vim
---> Running in 544047b8c170
Ign http://httpredir.debian.org jessie InRelease
Get:1 http://httpredir.debian.org jessie-updates InRelease [142 kB]
Get:2 http://httpredir.debian.org jessie Release.gpg [2373 B]
Get:3 http://httpredir.debian.org jessie Release [148 kB]
Get:4 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:5 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:6 http://httpredir.debian.org jessie/main amd64 Packages [9064 kB]
Get:7 http://security.debian.org jessie/updates/main amd64 Packages [390 kB]
Fetched 9828 kB in 2s (4030 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
The following extra packages will be installed:
libgpm2 vim-common vim-runtime
Suggested packages:
gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
libgpm2 vim vim-common vim-runtime
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 6218 kB of archives.
After this operation, 28.9 MB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main libgpm2 amd64 1.20.4-6.1+b2 [34.0 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main vim-common amd64 2:7.4.488-7 [184 kB]
Get:3 http://httpredir.debian.org/debian/ jessie/main vim-runtime all 2:7.4.488-7 [5047 kB]
Get:4 http://httpredir.debian.org/debian/ jessie/main vim amd64 2:7.4.488-7 [953 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 6218 kB in 0s (10.7 MB/s)
Selecting previously unselected package libgpm2:amd64.
Any idea why it is rebuilding the docker image every time?
Now you can enable docker layer caching on CircleCI.
It is a premium feature. It will reuse previous layers used to build your images.
https://circleci.com/docs/2.0/docker-layer-caching/