docker build -t rayalevinson/simpleweb .
docker build -t rayalevinson/posts:0.0.1 .
docker run [image id or image tag]
docker run -it [image id or image tag] [cmd]
[cmd] - overrides the default command
docker ps
docker exec -it [container id] [cmd]
docker logs [container id]
docker build -t rayalevinson/simpleweb .
docker run -p 5000:5000 rayalevinson/simpleweb
docker ps
docker exec -it
winpty docker exec -it
docker build .
package.json
{ "dependencies": { "express": "*" }, "scripts": { "start": "node index.js" } }
index.js
const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hi there'); }); const PORT = process.env.PORT || 5000; app.listen(PORT, () => { console.log(`App started on port ${PORT}`); });
Dockerfile
# Use and existing docker image as a base === # Specify a base image FROM node:alpine WORKDIR /usr/app # Download and install a dependency === COPY ./package.json ./ RUN npm install COPY ./ ./ # Tell the image what to do when it starts as a container === # Default command CMD ["npm", "start"]
.dockerignore
node_modules
docker build -t rayalevinson/simpleweb .
docker run -p 5000:5000 rayalevinson/simpleweb
docker run -p <route incoming requests to this port on local host> <this port
inside the container>
docker ps
docker exec -it <container id> sh
winpty docker exec -it <container id> sh
-it is - attach STDIN and and a nice looking terminal into the shell
We enter into the /usr/app
due to
WORKDIR /usr/app
in the Dockerfile
cd /
ls
http://localhost:5000
docker run -it rayalevinson/simpleweb sh
<-- override the default set of
commands by sh (shell)
winpty docker run -it rayalevinson/simpleweb sh
ls
The problem with this approach that we may accidentally to override files or folders inside the containerWORKDIR /usr/app
copy ./ ./
copy <path to folder to copy from on my machine relative to build context> <place to copy stuff to inside the container> ===
copy <path to the current working folder of the project> <path to the current working folder inside the container>