Docker Community Forums

Share and learn in the Docker community.

Adding a symlink inside the image

(Vanderkerkoff) #1

Hello there.

I’m sure I’m doing something silly, but I can’t seem to create a symlink in my image,which will then be present in my running container based on that image.

Here’s the relevant bit of the Dockerfile.

RUN mkdir /code
ADD . /code/
RUN pip install -r requirements.txt
RUN ln -s /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media /code/static/media/admin

The output from the build command says it’s doing it without errors, but when I then fire up the container with docker-compose, there is no symlink at that location.

Should I even be doing it in the Dockerfile, or in docker-compose.yml, and is that the correct syntax?

If I docker exec into the running container, running that exact code does create the symlink.

Thanks for any help or tips.

(shipshuk) #2

You can also try it to run with “docker run” command. I had the same issue you can call it something like this

docker exec 9ede507fa042 /bin/bash -c ‘uwsgi --ini /usr/src/app/nsfw/config/nsfw_uwsgi.ini --callable app && service nginx start’

I have run this after run in my case but I think you can run the same symlink script with “docker run” command as well.

Hope helps