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/
Related
Any Dockerfile I try to build, that includes apt-get update, just hangs indefinitely.
I can launch an image and run apt-get update inside the image with no problems.
docker run -it --entrypoint bash node:lts-bullseye
root#7b6ea3487aef:/# apt-get update
Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main arm64 Packages [120 kB]
Get:5 http://deb.debian.org/debian bullseye/main arm64 Packages [8070 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main arm64 Packages [2596 B]
Fetched 8392 kB in 2s (4936 kB/s)
Reading package lists... Done
root#7b6ea3487aef:/#
But if it's during the Docker build, it just hangs!
Update -
I installed lima and I'm able to build the image fine with -
lima nerdctl build .
So I think this must be Docker related
Dockerfile is nothing special - this is enough to reproduce the issue -
FROM node:lts-buster-slim
RUN apt-get update
"Hello, have you tried turning it off and on again"?
I just needed to restart the docker daemon.
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
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 get this error when running my pipeline file here is my pipeline file: I am a front-end Dev this is the first time build/creating a automative process like this any pointer on how to get it to work or improvement would be appreciated.
# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:10.9.0
pipelines:
branches:
master:
- step: max-time: 10
name: production
deployment: production
caches:
- node
script: # Modify the commands below to build your repository.
- npm install
- npm install -g #angular/cli#7.3.3
- ng build --prod
- apt-get clean
- apt-get update
- apt-get install ncftp
- ncftpput -v -u $FTP_USERNAME -p $FTP_PASSWORD -R $FTP_HOST $FTP_SITE_ROOT dist/*
- echo Finished uploading files to $FTP_HOST$FTP_SITE_R
definitions: caches: ncftp: /var/cache/apt node: node_modules
here is my error:
+ apt-get update
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 [825 kB]
Get:6 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 10.1 MB in 8s (1182 kB/s)
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.
I am not sure how to get apt-get to work in Bitbucket this pipeline file was working fine a couple of weeks ago. Any thoughts no what I can do to get it working again.
The node images should default to debian stretch instead of jessie now. Bitbucket may be caching the old image. You can force the stretch version by setting the image to node:<version>-stretch
Related issue on GitHub: https://github.com/nodejs/docker-node/issues/1013
I created a docker based en the following image:
https://hub.docker.com/r/tplatform/aws-linux-httpd24-php56/
I modified files an add new file in the /var/www folder in a running docker. I need to save this changes in new image but i dont know how can I do this. I checked docker commit but is not working for me.
Can you help me?
Docker commit is the tool to do what you asking. Probably you are using it wrong.
Example:
$ docker run -dit --name=Nginx -p 80:80 nginx
68188c608160754736f192d535742b9d0dfbc3c09564c1731741c08c211b219f
$ docker exec -it Nginx /bin/bash
root#68188c608160:/# touch New_file
root#68188c608160:/# apt-get update
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Ign:1 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [454 kB]
Get:4 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB]
Get:6 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2434 B]
Get:7 http://cdn-fastly.deb.debian.org/debian stretch-updates/main amd64 Packages [5152 B]
Get:8 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [7099 kB]
Fetched 7864 kB in 4s (1767 kB/s)
Reading package lists... Done
root#68188c608160:/# exit
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68188c608160 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp Nginx
$ docker commit Nginx nginx-updated:latest
sha256:dcc2f09f523eded0b2d33abb47e99b83453c12fb6ba958b441111f9ff40c5a8a
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-updated latest dcc2f09f523e 3 seconds ago 156MB
nginx latest dbfc48660aeb 2 weeks ago 109MB
The problem is this file: /tmp/install_and_run.sh.
In this file you can see a line with this content: echo "OK" > /var/www/html/index.html.
You modify the index.html content and commit it to a new image. After start this image as a container this shell file will be executed (Because is in the ENTRYPOINT of Dockerfile) and overwrite your content and insert OK in index.html again!
You can do this trick to solve it:
1. Create an index.html in this directory for example: /var/www/ and insert your contents to it.
2. Comment or remove this line in /tmp/install_and_run.sh : echo "OK" > /var/www/html/index.html
3. Place this code instead: cp /var/www/index.html /var/www/html/index.html
Then you can commit this image to a new one and will see your modifications are saved.