1

I have built nginx docker container for 6 months. Nginx in docker container show :

nginx version: nginx/1.9.5

And docker images show:

xxx/nginx80lb_release   latest              2228a5d98be7        8 months ago        132.9 MB

And dockerfile which I have built docker image before:

FROM nginx:latest

Now, I want to upgrade to latest nginx 1.11.2 (latest). I have searched in the google, but no luck. I don't want to rebuild docker image.

How can I do this? Please give me some advices.

Thank you!

Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
  • 1
    Not sure why you don't want to rebuild image. Another alternative is to go inside the container, upgrade nginx and do docker commit. – atv Jul 18 '16 at 04:22
  • Latest version on docker hub is 1.11.1 why not just use it? Run docker pull nginx:latest and you should be fine. – opHASnoNAME Jul 18 '16 at 04:23
  • If I rebuild the docker image, I have to configure SSL cert, load balancer and important thing I don't backup nginx file. – Thanh Nguyen Van Jul 18 '16 at 04:25
  • 2
    Then you are at a point where you need reconfigure your project using better practices. It isn't maintainable or efficient to do what you are trying to do beyond a basic testing/dev environment. – ldg Jul 18 '16 at 05:29
  • Show us your entire Dockerfile, there is gonna be a line that does the `apt-get install` command to install nginx – Samuel Toh Jul 18 '16 at 05:35
  • @SamuelToh, in this case nginx:latest is used as base image. So, there will not be any apt-get install nginx in Docker file. – atv Jul 18 '16 at 05:39
  • @atv thanks for the clarification. I guess OP doesn't have much choice but to rebuild the image or like you said hop in upgrade and commit it. I suspect OP isn't using volume? That is, data will be blown away as soon as the container is restarted. Hopefully this is not the case... – Samuel Toh Jul 18 '16 at 05:58
  • @SamuelToh yes, I didn't use volumn for this case. – Thanh Nguyen Van Jul 18 '16 at 06:46
  • 1
    @Thanh Nguyen Van Oh no! Better think of rescuing those important files inside the container before its too late! http://stackoverflow.com/questions/22049212/docker-copy-file-from-container-to-host And remember to use volume on your subsequent `start` or `run` command... – Samuel Toh Jul 18 '16 at 06:50
  • OR do `docker commit` to save the image state. – Samuel Toh Jul 18 '16 at 07:01

2 Answers2

3

You're using container and image pretty loosely here.

If you want to upgrade a container run docker exec -it <container_name> sh to get into it and run whatever commands you need to in container shell.

If you want to upgrade the image you can run a container based on it, make the same changes as above, then do docker commit.

johnharris85
  • 17,264
  • 5
  • 48
  • 52
3

Containers are based on immutable images.

You should not upgrade containers as you won’t be able to consistently re-create your env, that’s the whole point.

If you’ve bundled your secrets in your image... how are you rotating them / managing, that’s just very bad practice.

And: you can docker cp <container> file - copy out the certs.

Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53