By default, the Docker will expose port 8000
, so change this within the
Dockerfile if necessary. When ready, simply use the Dockerfile to
build the image.
docker build . -t node-api-docker
This will create the image and pull in the necessary dependencies.
Be sure to swap out ${package.json.version}
with the actual
version of API.
Once done, run the Docker image and map the port to whatever you wish on
your host. In this example, we simply map port 3000
of the host to
port 8000
of the Docker (or whatever port was exposed in the Dockerfile):
docker run -d -p 8000:3000 --restart=always --name=node-api-docker node-api-docker
Verify the deployment by navigating to your server address inyour preferred browser.
curl http://localhost:8000
view process:
ps -a
----------------------------------------------------------------------------------------------
login docker:
docker login
----------------------------------------------------------------------------------------------
list active containers:
docker container ls
----------------------------------------------------------------------------------------------
kill container process:
docker rm -f <CONTAINER_ID>
----------------------------------------------------------------------------------------------
building image in the container:
docker build . -t node-api-docker
----------------------------------------------------------------------------------------------
exec imagem in container:
docker run -p 8000:3000 node-api-docker
OBS: [external]8000:3000[internal]
!important: the next command exec with -e (envoriments of Docker with high priority)
docker run -p 8000:5000 -e PORT=9000 nodebr-api
----------------------------------------------------------------------------------------------
the below file is util in compacting files of deploy in the docker:
.dockerignore (file) example: /node_modules
----------------------------------------------------------------------------------------------
creting tags on Docker:
docker tag node-api-docker guizaramellaf/node-api-docker
----------------------------------------------------------------------------------------------
upping push to repository:
docker push guizaramellaf/node-api-docker
more: hub.docker.com
“O espaço entre a teoria e a prática não é tão grande como é, a teoria na prática.”
Requires Node.js v17+ to run.
Install the dependencies and devDependencies and start the server.
npm i // download node_modules
npm run dev // run in nodemon mod
npm start // default run
Plugin | README |
---|---|
Express | Click Here |
Free Software, Hell Yeah!