Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker run sed doesn't work

Tags:

docker

sed

I'm approaching to Docker. I created an image debootstraping Debian Jessie and I want to add the contrib section to APT sources file.

/etc/apt/sources.list contents are:

$ docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main

I want them to be:

deb http://debian.fastweb.it/debian jessie main contrib
deb http://debian.fastweb.it/debian jessie-updates main contrib
deb http://security.debian.org/ jessie/updates main contrib

So I ran this command:

docker run some/image sed -i 's/main/main contrib/g' /etc/apt/sources.list

Which exits without errors; but it doesn't update /etc/apt/sources.list contents:

$ docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main
like image 533
mdesantis Avatar asked Mar 13 '14 10:03

mdesantis


1 Answers

You did not change the image. You started a container, based on the image. Then you ran your sed command and changed the file contents. Check docker ps -a to see the id of the container that just closed. If you use docker cp to extract your file you should see that it was changed as expected (assuming your sed command was ok).

You could also create a Dockerfile

FROM some/image
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list
# this command is just temporary, you probably are going to do something else
CMD cat /etc/apt/sources.list

and run the new image docker run some/new-image to get the expected output.

Conclusion - you probably want to do run your sed command in the original images Dockerfile.

like image 75
qkrijger Avatar answered Sep 28 '22 00:09

qkrijger