Hi,
It's strange that FULL docker image does not contain node.js.
We have to spend time installing many things...
Out of curiosity, what nodejs/npm versions you install manually, @freerider7777 ?
Looking at Debian stretch, it ships nodejs 4.8.3 and doesnt ship npm; so we might want to wait for Buster to be released, rebase our Dockerfiles on top of it, and get node 10 / npm 5 out of the box.
I think I had installed 12 ... I'll repeat it now, as in your help docker is run with --rm and now the container is gone :(
( https://unit.nginx.org/howto/docker/ )
10 is also ok, but we also need to install
apt install unit-dev
also node-gyp and unit-http
as I understand
Additionally, I think it would be awesome if there were a node (or node10/node12) image variant that already has Node and unit-http globally installed. Would massively simplify the setup process as we could just copy in app files and run npm link unit-http.
Meanwhile we've updated Docker howto on the website: https://unit.nginx.org/howto/docker/?1561069119
Please feel free to share any feedback if anything is unclear or there's something else to be added.
@dylan-kerr Yeah, docker is supposed to simplify things- "pull and run", not "pull, install 10 more things and maybe run" :)
BTW, is it on purpose here:
https://unit.nginx.org/howto/docker/
that you are using different ports (8080 -> 8000)?
-p 8080:8000 nginx/unit:latest
not the same
This allows to visually distinguish host/container ports easier. Otherwise, there's nothing special about the difference.
Meanwhile, you may find our new containerization howto helpful: http://unit.nginx.org/howto/docker/#containerizing-apps
Thanks, I'll try.
BTW, is it on purpose that here ports are the same? :))
docker run -d -p 8080:8080 unit-expressapp
@artemkonev Thank you for adding that section to the docs, that's incredibly helpful!
One thing I have found playing around with that example this evening is that the Dockerfile doesn't appear to make very good use of caching - whenever the application or unit config.json is changed, the entire installation process needs to be re-run. I was able to improve this (without significant change to the image size) by separating the runtime installation from the code+config step:
# keep our base image as small as possible
FROM nginx/unit:1.9.0-minimal
# add NGINX Unit and Node.js repos
RUN apt update \
&& apt install -y apt-transport-https gnupg1 \
&& curl https://nginx.org/keys/nginx_signing.key | apt-key add - \
&& echo "deb https://packages.nginx.org/unit/debian/ stretch unit" \
> /etc/apt/sources.list.d/unit.list \
&& echo "deb-src https://packages.nginx.org/unit/debian/ stretch unit" \
>> /etc/apt/sources.list.d/unit.list \
&& curl https://deb.nodesource.com/setup_12.x | bash - \
# install build chain
&& apt update \
&& apt install -y build-essential nodejs unit-dev \
# add dependencies locally
&& npm install -g --unsafe-perm unit-http \
# final cleanup
&& apt remove -y build-essential unit-dev apt-transport-https gnupg1 \
&& apt clean && apt autoclean && apt autoremove --purge -y \
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list
# same as "working_directory" in config.json
COPY myapp/ /www
# port used by the listener in config.json
EXPOSE 8080
RUN cd /www && npm link unit-http && npm install express \
# launch Unit for initial config
&& unitd --control unix:/var/run/control.unit.sock \
# configure the app in Unit
&& curl -X PUT --data-binary @/www/config.json --unix-socket \
/var/run/control.unit.sock http://localhost/config/ \
# app dir cleanup
&& rm /www/config.json
Thank you. The idea behind the update was to provide details of Unit-specific actions in a concise basic sample; of course, such separation would better suit larger production scenarios. Also, if you need to update the config only, another option is docker exec to supply Unit with a mounted config file in an existing container.
What about .dockerignore in documentation?
@dylan-kerr We've updated the section, thank you for your input: http://unit.nginx.org/howto/docker/#containerizing-apps
@freerider7777 If you mean using it with node_modules, this is more of a Node/Docker thing not specific to Unit.