Last active
April 13, 2022 11:54
-
-
Save ObjectIsAdvantag/7e03a8695cc8aa6c99cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1st step : Create a Dockerfile | |
------------------------------- | |
> touch Dockerfile | |
> notepad Dockerfile | |
''' | |
# Start from argon (latest long term supported version of node) | |
# - argon : Full node dev env (640 MB) | |
# - argon-slim : Full node dev env (200 MB) | |
FROM node:argon-slim | |
# install sails | |
RUN npm -g install sails | |
# create user node | |
RUN useradd -c 'Node.js user' -m -d /home/node -s /bin/bash node | |
USER node | |
## expose port for future sails lift | |
EXPOSE 1337 | |
''' | |
2nd step : Build your image | |
--------------------------- | |
> docker build -t ssfartz/sails-slim . | |
... see outputs ... | |
> docker images | |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | |
ssfartz/sails-slim latest 9c744e85fd2b About an hour ago 299.6 MB | |
node argon f27d7e53a0f1 7 days ago 641.8 MB | |
node argon-slim 48d1423a3d00 12 days ago 204.9 MB | |
3rd step : Play with sailsjs | |
---------------------------- | |
# TODO : give a name to the contains | |
> docker run -it --name demo -p 8080:1337 --rm ssfartz/sails-slim:v1 /bin/bash | |
# interact with sails... | |
node@docker$ sails new demo | |
node@docker$ cd demo | |
node@docker$ sails generate api user | |
node@docker$ sails lift | |
node@docker$ CTRL-Z // detach from process | |
node@docker$ bg | |
node@docker$ CTRL-P, CTRL-Q // detach container | |
# Open a Web browser, see the results | |
> start 192.168.99.101:8080 | |
> docker logs -f demo // -f to see logs in streaming mode | |
Annexe 1 - Outputs | |
------------------ | |
Sending build context to Docker daemon 2.048 kB | |
Step 1 : FROM node:argon | |
---> f27d7e53a0f1 | |
Step 2 : RUN npm install -g node | |
---> Running in 00ff8f224b53 | |
npm info it worked if it ends with ok | |
npm info using [email protected] | |
npm info using [email protected] | |
npm info attempt registry request try #1 at 10:10:38 AM | |
npm http request GET https://registry.npmjs.org/node | |
npm http 200 https://registry.npmjs.org/node | |
npm WARN deprecated [email protected]: To update or install node, go to http://nodejs.org/ | |
npm info retry fetch attempt 1 at 10:10:39 AM | |
npm info attempt registry request try #1 at 10:10:39 AM | |
npm http fetch GET https://registry.npmjs.org/node/-/node-0.0.0.tgz | |
npm http fetch 200 https://registry.npmjs.org/node/-/node-0.0.0.tgz | |
npm info install [email protected] into /usr/local/lib | |
npm info installOne [email protected] | |
npm info preinstall [email protected] | |
npm info build /usr/local/lib/node_modules/node | |
npm info linkStuff [email protected] | |
npm info install [email protected] | |
npm info postinstall [email protected] | |
[email protected] /usr/local/lib/node_modules/node | |
npm info ok | |
---> 9a7948dbd2fb | |
Removing intermediate container 00ff8f224b53 | |
Step 3 : EXPOSE 1337 | |
---> Running in fa36ace62a9b | |
---> 6c70a8d8c3b9 | |
Removing intermediate container fa36ace62a9b | |
Successfully built 6c70a8d8c3b9 | |
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended | |
to double check and reset permissions for sensitive files and directories. | |
Спасибо!
For anybody finding this gist in 2022 (like me) - you'll want to use a more recent version of Node at the top of the Dockerfile!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent walk through here.