So I pulled down the opensuse Docker--only 94M, nice!
I created a Docker file like this:
FROM opensuse
RUN zypper --non-interactive install tar
RUN zypper --non-interactive clean -a
RUN rm -rf /var/log/zypp /var/log/zypper.log
The 'tar' command and its dependencies require ~3M, but the resulting image is 140M! I've cleaned the cache and killed the logs, so what else is causing the roughly 40M bloat here?
You need to do the whole operation in one RUN command
RUN zypper --non-interactive install tar \
&& zypper --non-interactive clean -a \
&& rm -rf /var/log/zypp /var/log/zypper.log
As docker does a commit after each line
redacted history
$ docker history test
IMAGE CREATED CREATED BY SIZE COMMENT
f0c1173538b0 2 minutes ago /bin/sh -c zypper --non-interactive install t 7.429 MB
80bd0f661aef 3 weeks ago /bin/sh -c #(nop) ADD file:4c338e205c079dbf5d 97.78 MB
da0e7dee81d7 8 weeks ago /bin/sh -c #(nop) MAINTAINER Flavio Castelli 0 B
Related
Rather than necro-post on a two-year old thread, I decided to create a new question.
I want add brew (homebrew) to a Docker container, but I get a brew: not found error.
The suggested solution in that previous article doesn't seem to work. This new Dockerfile...
FROM rust:1.63.0-buster
WORKDIR app
RUN apt-get update && \
apt-get install -y -q --allow-unauthenticated \
git \
sudo
RUN useradd -m -s /bin/zsh linuxbrew && \
usermod -aG sudo linuxbrew && \
mkdir -p /home/linuxbrew/.linuxbrew && \
chown -R linuxbrew: /home/linuxbrew/.linuxbrew
USER linuxbrew
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
USER root
RUN chown -R $CONTAINER_USER: /home/linuxbrew/.linuxbrew
RUN brew install hello
gives this error... What am I missing? Thanks.
=> ERROR [6/6] RUN brew install hello 0.2s
------
> [6/6] RUN brew install hello:
#9 0.181 /bin/sh: 1: brew: not found
------
executor failed running [/bin/sh -c brew install hello]: exit code: 127
This Dockerfile installs brew in /home/linuxbrew/.linuxbrew/bin/brew. Including that directory in the path (with the ENV command) does the trick.
...
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"
RUN brew install hello
Has anyone ever installed the AWS CloudWatch in the Alpine docker? Seems to me it is not supporting for all the installation packages AWS provided.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html
We can install in this way:
RUN apk update && apk add ca-certificates curl rpm
RUN wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
RUN rpm -ihv --nodeps ./amazon-cloudwatch-agent.rpm
But it is not functioning correctly. If I want to check its status
~/test # /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
I get the error.
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl: line 469: systemctl: not found
For me, I don't think it is not compatible in Alpine (I am using alpine:3.14). Anyone has some idea on this?
Thanks,
#To install aws-cloudwatch-agent
RUN apk update && apk add ca-certificates curl rpm
RUN wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
RUN rpm -ihv --nodeps ./amazon-cloudwatch-agent.rpm
#To setup repo for k6 and install k6
ENV RUN_IN_CONTAINER="True"
RUN wget https://dl.cloudsmith.io/public/cloudposse-dev/packages/alpine/any-version/main/x86_64/k6-0.34.1-r0.apk
RUN apk add --allow-untrusted k6-0.34.1-r0.apk ```
Thanks in advance!
RD
Seems just need to use the docker multiple stages to build what you want:
If we want to do the integration of K6 and AWS CloudWatch (to make them in one docker files with Alpine.
Checkout git#github.com:grafana/k6.git
Update the docker files to
FROM golang:1.17-alpine as builder_k6
WORKDIR $GOPATH/src/go.k6.io/k6
ADD . .
RUN apk --no-cache add git
RUN CGO_ENABLED=0 go install -a -trimpath -ldflags "-s -w -X go.k6.io/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"
FROM debian:latest as builder_cw
RUN apt-get update && \
apt-get install -y ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
RUN curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb && \
dpkg -i -E amazon-cloudwatch-agent.deb && \
rm -rf /tmp/* && \
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard && \
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl && \
rm -rf /opt/aws/amazon-cloudwatch-agent/bin/config-downloader
FROM alpine:latest
COPY --from=builder_cw /tmp /tmp
COPY --from=builder_cw /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder_cw /opt/aws/amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent
COPY --from=builder_k6 /go/bin/k6 /usr/bin/k6
ADD statsd.json /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json
ADD statsd.json /opt/aws/amazon-cloudwatch-agent/etc/statsd.json
ADD credentials /root/.aws/credentials
ADD config /root/.aws/config
#startup the agent
ENV RUN_IN_CONTAINER="True"
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]
I have following file structure
Django/
- IoT.yml
- Dockerfile_Build_Django
- requirements.txt
My dockerfile (Dockerfile_Build_Django) for budiding image is as below:
FROM python:3.10.0a7-alpine3.13
ENV PYTHONUNBUFFERED 1
RUN mkdir /code/
WORKDIR /usr/src/app
COPY . .
RUN pip install -r requirements.txt
My docker-compose file as below:
Django_2.2:
build:
context: ./
dockerfile: Dockerfile_Build_Django
# Give an image name/tag
image: python:3.10.0a7-alpine3.13
container_name: Django_2.2
depends_on:
- Django_Mongo_4.2.12
tty: true
after "docker-compose -f IoT.yml up" to setup and run container, then I use "docker exec -it Django_2.2 /bin/sh" to SSH access the Django_2.2 container, I found:
no folder "/code" was created according to "RUN mkdir /code/" in docker file
nothing was copied over to working directory according to dockerfile.
Django was not installed according to above dockerfile.
[root#Mysite Django]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
python 3.10.0a7-alpine3.13 bba91cdea5a1 3 days ago 44.9MB
django_2.2 iot 37c35b93c3d8 6 days ago 86.3MB
[root#MySite Django]# docker history python:3.10.0a7-alpine3.13
IMAGE CREATED CREATED BY SIZE COMMENT
bba91cdea5a1 3 days ago /bin/sh -c #(nop) CMD ["python3"] 0B
<missing> 3 days ago /bin/sh -c set -ex; wget -O get-pip.py "$P… 8.01MB
<missing> 3 days ago /bin/sh -c #(nop) ENV PYTHON_GET_PIP_SHA256… 0B
<missing> 3 days ago /bin/sh -c #(nop) ENV PYTHON_GET_PIP_URL=ht… 0B
<missing> 3 days ago /bin/sh -c #(nop) ENV PYTHON_PIP_VERSION=21… 0B
<missing> 3 days ago /bin/sh -c cd /usr/local/bin && ln -s idle3… 32B
<missing> 3 days ago /bin/sh -c set -ex && apk add --no-cache --… 29.5MB
<missing> 3 days ago /bin/sh -c #(nop) ENV PYTHON_VERSION=3.10.0… 0B
<missing> 10 days ago /bin/sh -c #(nop) ENV GPG_KEY=A035C8C19219B… 0B
<missing> 10 days ago /bin/sh -c set -eux; apk add --no-cache c… 1.76MB
<missing> 10 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B
<missing> 11 days ago /bin/sh -c #(nop) ENV PATH=/usr/local/bin:/… 0B
<missing> 11 days ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 11 days ago /bin/sh -c #(nop) ADD file:7119167b56ff1228b… 5.61MB
[root#MySite Django]# docker-compose -f IoT.yml build
Django_Mongo_4.2.12 uses an image, skipping
Building Django_2.2
Sending build context to Docker daemon 2.832MB
Step 1/7 : FROM python:3.10.0a7-alpine3.13
---> bba91cdea5a1
Step 2/7 : ENV PYTHONUNBUFFERED 0
---> Running in 4f04eff80f44
Removing intermediate container 4f04eff80f44
---> 894fa6105e9b
Step 3/7 : RUN mkdir /code/
---> Running in 41a547193037
Removing intermediate container 41a547193037
---> 08d8a6605228
Step 4/7 : WORKDIR /usr/src/app
---> Running in 1d33ed47543f
Removing intermediate container 1d33ed47543f
---> f4f22bc9b3bb
Step 5/7 : COPY . .
---> 317348f86075
Step 6/7 : RUN pip install --upgrade pip
---> Running in e43752bea2dd
Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (21.0.1)
Removing intermediate container e43752bea2dd
---> 1ce0ff9deb41
Step 7/7 : RUN pip install -r requirements.txt
---> Running in 87fb8a9db240
Collecting Django==2.2.17
Downloading Django-2.2.17-py3-none-any.whl (7.5 MB)
Collecting pytz
Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
Installing collected packages: sqlparse, pytz, Django
Successfully installed Django-2.2.17 pytz-2021.1 sqlparse-0.4.1
Removing intermediate container 87fb8a9db240
---> 8471de36ee4d
Successfully built 8471de36ee4d
Successfully tagged python:3.10.0a7-alpine3.13
[root#MySite Django]#
[root#MySite Django]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
python 3.10.0a7-alpine3.13 8471de36ee4d 8 minutes ago 86.5MB
python <none> bba91cdea5a1 3 days ago 44.9MB
django_2.2 iot 37c35b93c3d8 6 days ago 86.3MB
Am I missing some steps from the Docker documentation?
delete my previously-built image, and run docker-compose again, it now build a new image and executing all RUN / COPY / CMD commands in dockerfile. All work perfectly.
Based on above behavior, it seems that "image: " line in docker-compose file asks docker daemon to check if this image exist locally. If yes, then directly use it without building a new one. When I delete that image manually, docker daemon can not find that image, hence build a new one.
According to Docker official guide, https://docs.docker.com/compose/compose-file/compose-file-v3/#build,
"image: " line is only for rename final image, never say it would check if image already existed, and possibly impacting image building. The official guide is not precise and accurate in this regard.
I am building my dockerfile using Redhat UBI image, and when I build the image I get the wget: unable to resolve host address'github.com'.
I have tried adding a different URL that does not start with GitHub and that works. Not sure what the problem is.
Below are the errors logs i get when i build the docker file with : wget: unable to resolve host address 'github.com'
Step 11/25 : RUN set -ex; apk update; apk add -f acl dirmngr gpg lsof procps wget netcat gosu tini; rm -rf /var/lib/apt/lists/*; cd /usr/local/bin; wget -nv https://github.com/apangin/jattach/releases/download/v1.5/jattach; chmod 755 jattach; echo >jattach.sha512 "d8eedbb3e192a8596c08efedff99b9acf1075331e1747107c07cdb1718db2abe259ef168109e46bd4cf80d47d43028ff469f95e6ddcbdda4d7ffa73a20e852f9 jattach"; sha512sum -c jattach.sha512; rm jattach.sha512
---> Running in 3ad58c40b25a
+ apk update
fetch https://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v20200917-1125-g7274a98dfc [https://dl-cdn.alpinelinux.org/alpine/edge/main]
v20200917-1124-g01e8cb93ff [https://dl-cdn.alpinelinux.org/alpine/edge/community]
OK: 13174 distinct packages available
+ apk add -f acl dirmngr gpg lsof procps wget netcat gosu tini
(1/12) Installing libacl (2.2.53-r0)
(2/12) Installing acl (2.2.53-r0)
(3/12) Installing lsof (4.93.2-r0)
(4/12) Installing libintl (0.20.2-r0)
(5/12) Installing ncurses-terminfo-base (6.2_p20200918-r1)
(6/12) Installing ncurses-libs (6.2_p20200918-r1)
(7/12) Installing libproc (3.3.16-r0)
(8/12) Installing procps (3.3.16-r0)
(9/12) Installing tini (0.19.0-r0)
(10/12) Installing libunistring (0.9.10-r0)
(11/12) Installing libidn2 (2.3.0-r0)
(12/12) Installing wget (1.20.3-r1)
Executing busybox-1.32.0-r3.trigger
OK: 9 MiB in 26 packages
+ rm -rf '/var/lib/apt/lists/*'
+ cd /usr/local/bin
+ wget -nv https://github.com/apangin/jattach/releases/download/v1.5/jattach
wget: unable to resolve host address 'github.com'
The command '/bin/sh -c set -ex; apk update; apk add -f acl dirmngr gpg lsof procps wget netcat gosu tini; rm -rf /var/lib/apt/lists/*; cd /usr/local/bin; wget -nv https://github.com/apangin/jattach/releases/download/v1.5/jattach; chmod 755 jattach; echo >jattach.sha512 "d8eedbb3e192a8596c08efedff99b9acf1075331e1747107c07cdb1718db2abe259ef168109e46bd4cf80d47d43028ff469f95e6ddcbdda4d7ffa73a20e852f9 jattach"; sha512sum -c jattach.sha512; rm jattach.sha512' returned a non-zero code: 4
Here is my docker file that I have which I build to create the image
FROM alpine: edge as BUILD
LABEL maintainer="Project Ranger team <mbyousaf#deloitte.co.uk>"
LABEL repository="https://github.com/docker-solr/docker-solr"
ARG SOLR_VERSION="8.6.2"
ARG SOLR_SHA512="0a43401ecf7946b2724da2d43896cd505386a8f9b07ddc60256cb586873e7e58610d2c34b1cf797323bf06c7613b109527a15105dc2a11be6f866531a1f2cef6"
ARG SOLR_KEYS="E58A6F4D5B2B48AC66D5E53BD4F181881A42F9E6"
# If specified, this will override SOLR_DOWNLOAD_SERVER and all ASF mirrors. Typically used downstream for custom builds
ARG SOLR_DOWNLOAD_URL
# Override the solr download location with e.g.:
# docker build -t mine --build-arg SOLR_DOWNLOAD_SERVER=http://www-eu.apache.org/dist/lucene/solr .
ARG SOLR_DOWNLOAD_SERVER
RUN set -ex; \
apk add --update; \
apk add -f install acl dirmngr gpg lsof procps wget netcat gosu tini; \
rm -rf /var/lib/apt/lists/*; \
cd /usr/local/bin; wget -nv https://github.com/apangin/jattach/releases/download/v1.5/jattach; chmod 755 jattach; \
echo >jattach.sha512 "d8eedbb3e192a8596c08efedff99b9acf1075331e1747107c07cdb1718db2abe259ef168109e46bd4cf80d47d43028ff469f95e6ddcbdda4d7ffa73a20e852f9 jattach"; \
sha512sum -c jattach.sha512; rm jattach.sha512
I would check whether you can resolve github.com on your host where you're doing this build, and I would cat /etc/resolv.conf to see the resolvers of your host. If github.com resolves on your host (which you can see via nslookup github.com), then I would try to use the resolvers explicitly by either configuring the Docker daemon to use it as seen here and here or I would try to do it at a per command level as suggested in an answer here, which is kind of creative.
RUN echo "nameserver XX.XX.XX.XX" > /etc/resolv.conf && \
command_depending_on_dns_resolution
I have a simple Dockerfile that downloads the node.js source tarball, checksums it, extracts it, builds and installs it. The checksum works when manually run in an interactive docker container, but fails when running the exact same commands when building a Dockerfile.
Works:
docker run -i -t ubuntu:12.04 /bin/bash
cd /tmp
apt-get update -y
apt-get install wget build-essential automake -y
wget http://nodejs.org/dist/latest/node-v0.10.26.tar.gz
wget http://nodejs.org/dist/latest/SHASUMS256.txt
sha256sum -c SHASUM256.txt 2>&1|grep -qs OK
tar -xvf node-v0.10.26.tar.gz && cd node-v0.10.26
./configure && make && make install
Doesn't work:
sudo docker build -t="my_docker_node_image_01" .
Error is:
sudo docker build -t="my_docker_node_image_01" .
Uploading context 7.168 kB
Uploading context
Step 0 : FROM ubuntu:12.04
---> 9cd978db300e
Step 1 : RUN cd /tmp
---> Using cache
---> 0467ad75bbd6
Step 2 : RUN apt-get update -y
---> Using cache
---> d2933f250090
Step 3 : RUN apt-get install wget build-essential automake -y
---> Using cache
---> e8a71b28782a
Step 4 : RUN wget http://nodejs.org/dist/latest/node-v0.10.26.tar.gz
---> Using cache
---> bae7de7b46f7
Step 5 : RUN wget http://nodejs.org/dist/latest/SHASUMS256.txt
---> Using cache
---> 245f6b6ceb84
---> 77532c879864
Step 6 : RUN sha256sum -c SHASUM256.txt 2>&1|grep -qs OK
---> Running in 77765e80f55b
2014/04/22 22:27:32 The command [/bin/sh -c sha256sum -c SHASUM256.txt 2>&1|grep -qs OK] returned a non-zero code: 1
I tried adding less SHASUMS256.txt to the Dockerfile just to confirm that file is successfully downloaded uncorrupted, and it is, but still getting the error anyway.
I'm not sure how to troubleshoot this since normally I would just manually run all the steps in an interactive container to see what goes wrong. Any suggestions much appreciated.
I think I figured this out and it's just a typo, at least when I cut and paste your commands above! You download SHASUMS256.txt but test against a file called SHASUM256.txt (missing the S). Because you throw away the output and pipe it to grep, you weren't seeing that error.
$ sha256sum -c SHASUM256.txt
sha256sum: SHASUM256.txt: No such file or directory
$ sha256sum -c SHASUM256.txt 2>&1|grep -qs OK
$ echo $?
1
Doing an echo $? tells you the return code of the last command executed (in this case 1). By correcting the file, it works for me now:
$ sha256sum -c SHASUMS256.txt 2>&1|grep -qs OK
$ echo $?
0