-
Notifications
You must be signed in to change notification settings - Fork 466
/
Introduction to Docker
51 lines (36 loc) · 1.32 KB
/
Introduction to Docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mkdir test && cd test
cat > Dockerfile <<EOF
# Use an official Node runtime as the parent image
FROM node:lts
# Set the working directory in the container to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Make the container's port 80 available to the outside world
EXPOSE 80
# Run app.js using node when the container launches
CMD ["node", "app.js"]
EOF
cat > app.js << EOF;
const http = require("http");
const hostname = "0.0.0.0";
const port = 80;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World\n");
});
server.listen(port, hostname, () => {
console.log("Server running at http://%s:%s/", hostname, port);
});
process.on("SIGINT", function () {
console.log("Caught interrupt signal and will exit");
process.exit();
});
EOF
docker build -t node-app:0.1 .
docker run -p 4000:80 --name my-app node-app:0.1
gcloud artifacts repositories create my-repository --repository-format=docker --location=us-central1 --description="Docker repository"
gcloud auth configure-docker us-central1-docker.pkg.dev
docker build -t us-central1-docker.pkg.dev/qwiklabs-gcp-00-8ce007aa4ffa/my-repository/node-app:0.2 .
docker push us-central1-docker.pkg.dev/qwiklabs-gcp-00-8ce007aa4ffa/my-repository/node-app:0.2