0

I pulled a container from public repo and I want to install an package to it. But no success... Any help, please ? How to make the setting for docker's connectivity to package repositories ?

[root@adf2 adf2_umb_docker]# docker ps -l

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

8a9a015c5301 devcafe/cmake-cookbook_circleci_ubuntu16.04-pgi18.4 "bash" 8 minutes ago Up 8 minutes admiring_shirley

[root@adf2 adf2_umb_docker]# docker run devcafe/cmake-cookbook_circleci_ubuntu16.04-pgi18.4 bash -c "apt-get -y install vim"

Reading package lists...

Building dependency tree...

Reading state information...

E: Unable to locate package vim

Admin informed me about this log from the firewall:

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C OUTPUT -m addrtype --dst-type LOCAL -j DOCKER ! --dst 127.0.0.0/8' failed: iptables: No chain/target/match by that name.

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -j DOCKER' failed: iptables: No chain/target/match by that name.

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -j DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name.

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -s 192.168.0.0/20 ! -o docker0 -j MASQUERADE' failed: iptables: No chain/target/match by that name.

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -i docker0 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 -o docker0 -j ACCEPT' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 ! -o docker0 -j ACCEPT' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Aug 23 23:02:08 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Aug 23 23:02:09 adf2 firewalld[5882]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -j DOCKER' failed: iptables: No chain/target/match by that name.

0

That's not how you add a package in Docker. With your method have a container instance add a package to itself.. That makes the container attempt to access the internet, which may be forbidden by local rules. This also creates future problems:

  • How to you backup this container
  • How to you rebuild it if necessary

The correct way is to derive the image, using a Dockerfile:

FROM devcafe/cmake-cookbook_circleci_ubuntu16.04-pgi/18.4
RUN apt-get -y install vim

Then you create the image using:

docker build -t "TheDerivedImageName" $TheDirectpryWithTheDockerfFile

And when necessary run the image, by creating a container instance from it:

docker run TheDerivedImageName

The Dockerfile and associated files are host files: they can be backed up, put in a source control system (git...), shared with other people...

Furthermore, installing Vim in the docker image is unnecessary and hints that you maybe not using Docker properly. If you need to create/edit files in the container, you either:

  • Put them in the image at build time using a COPY statement in the Dockerfile
  • Share a file or directory on the host wit the container using a "bind mount", and edit them from the host.
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.