Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - centos 7 CMD yum commands run but don't install

Tags:

docker

centos

yum

I'm fairly new to Docker, and when attempting to install packages via the "Dockerfile" I've noticed that the build steps pass, but when i connect to the docker and load a shell, none of the packages have actually been installed.

Config:

FROM centos:latest
CMD yum -y install epel-release
CMD yum -y install collectd

Build steps:

Sending build context to Docker daemon 40.45 kB
Step 1/3 : FROM centos:latest
---> 67591570dd29
Step 2/3 : CMD yum -y install epel-release
 ---> Using cache
 ---> 4148233bce10
Step 3/3 : CMD yum -y install collectd
---> Using cache
---> 62998bf2ce0f

When connecting to the docker neither package is installed, but I am able to install the packages within the docker:

[root@cassiopeia monitoringDocker]# docker exec -it 0579169abb44 bash
[root@0579169abb44 /]# yum -y install epel-release
Loaded plugins: fastestmirror, ovl
base

Please help!

like image 280
Xerphiel Avatar asked Feb 05 '23 05:02

Xerphiel


1 Answers

Use like

FROM centos:latest
RUN \
  yum -y install epel-release && \
  yum -y install collectd

OR

FROM centos:latest
RUN yum -y install epel-release collectd

RUN :

RUN instruction allows you to install your application and packages requited for it. It executes any commands on top of the current image and creates a new layer by committing the results.

CMD :

CMD instruction allows you to set a default command, which will be executed only when you run container without specifying a command. If Docker container runs with a command, the default command will be ignored.

like image 113
pl_rock Avatar answered Feb 13 '23 03:02

pl_rock