Create image from running docker - docker

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.

Related

Why I cannot run `apt update` inside a fresh ubuntu:22.04? [closed]

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.

`apt-get update` never completes in Docker build

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.

apt and apt-get in Dockerfile returning error

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>

Pipeline apt-get update Fails

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

Caching Docker images in CircleCI

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/

Resources