-
cari image hello-world di local, jika tidak ada, docker akan mencari di docker hub
docker run hello-world
-
command untuk melihat image yang ada di local
docker images
-
coba jalankan image yang sudah ada di local
docker run hello-world
-
Lihat container yang sedang berjalan
docker ps
-
Lihat semua container yang pernah berjalan
docker ps -a
-
Buat directory dan masuk ke directory tersebut
mkdir test && cd test
-
Buat DOCKERFILE
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
-
Buat aplikasi nodejs
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
-
Build image
docker build -t node-app:0.1 .
-
Lihat image yang sudah dibuat
docker images
-
Jalankan image yang sudah dibuat
docker run -p 4000:80 --name my-app node-app:0.1
-
Lihat aplikasi yang sudah berjalan di terminal lain
curl http://localhost:4000
-
Tutup terminal yang menjalankan aplikasi
-
Stop n remove container
docker stop my-app && docker rm my-app
-
Jalankan lagi
docker run -p 4000:80 --name my-app -d node-app:0.1 docker ps
-
Lihat log aplikasi
docker logs [container_id]
-
ganti file app.js ("ganti respond nya aja")
-
Build image baru
docker build -t node-app:0.2 .
-
Jalankan image baru
docker run -p 8080:80 --name my-app-2 -d node-app:0.2 docker ps
-
Lihat aplikasi terbaru
curl http://localhost:8080
-
Lihat log
docker logs -f [container_id]
-
bash ke container
docker exec -it [container_id] bash
-
Lihat direktori
ls
-
Exit
exit
-
Lihat metadata container
docker inspect [container_id]
-
Lihat metadata image dengan format
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [container_id]
Navigation Menu > CI/CD > Artifact Registry > Repositories
Create Repository
-
Auth
gcloud auth configure-docker us-central1-docker.pkg.dev
-
Set project id environment variable
export PROJECT_ID=$(gcloud config get-value project) cd ~/test
-
Tag image
docker tag node-app:0.2 us-central1-docker.pkg.dev/${PROJECT_ID}/node-app:0.2
-
Push image
docker push us-central1-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2
-
Stop container
docker stop $(docker ps -q) docker rm $(docker ps -aq)
-
Remove image
docker rmi us-central1-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2 docker rmi node:lts docker rmi -f $(docker images -aq) # remove remaining images docker images
-
Pull and Run images from Artifact Registry
docker pull us-central1-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2 docker run -p 4000:80 -d us-central1-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2 curl http://localhost:4000