How to install multiple packages using apt-get via a Dockerfile
docker
Solution
Couple of pointers / comments here:
- It's `ubuntu` not `Ubuntu`
- From base `ubuntu` (and unfortunately, a lot of images) you don't need to use `sudo`, the default user is `root` (and in `ubuntu`, `sudo` is not included anyway)
- You want your `apt-get update` and `apt-get install` to be `RUN` as part of the same command, to prevent issues with Docker's layer cache
- You need to use the `-y` flag to apt-get install as the Docker build process runs non-interactively
- Few other points I could make about clearing up your apt-cache and other non-required artifacts after running the commands, but this should be enough to get going on
New Dockerfile (taking into account the above) would look something like:
FROM ubuntu
MAINTAINER example
#install and source ansible
RUN apt-get update && apt-get install -y \
git \
python-yaml \
python-jinja2 \
python-pycurl
RUN git clone https://github.com/ansible/ansible.git
WORKDIR ansible/hacking
RUN chmod +x env-setup; sync \
&& ./env-setup
You might also find it useful to read the Dockerfile best practises.
Edit: Larsks answer also makes some useful points about the state of the container not persisting between layers so you should go upvote him too!
Problem
So I am trying to make a basic Dockerfile, but when I run this it says ``` The command bin/sh -c sudo apt-get install git python-yaml python-jinja2 returned a non-zero code: 1 ``` My question is what am I doing wrong here, and is it even allowed to do commands like 'cd' and 'source' from the Dockerfile? ``` FROM Ubuntu MAINTAINER example #install and source ansible RUN sudo apt-get update RUN sudo apt-get install git python-yaml python-jinja2 python-pycurl RUN sudo git clone https://github.com/ansible/ansible.git RUN sudo cd ansible RUN sudo source ./hacking/env-setup ```