Summary of Docker understanding by beginners ⑤ ~ Until deploying docker container on EC2 instance ~

Introduction

Now that I've finally started learning Docker, I'll summarize my understanding.

What i did

Upload local PC code to EC2 via Github

First, log in to your EC2 instance

Assuming you have a key pair in ~ / .ssh on your local PC

cd ~/.ssh
ssh -i "ec2-key.pem" ec2-user@<public-ip>

Create a key on your EC2 instance

ssh-keygen -t rsa

You will be asked for a passphrase, so enter the passphrase if necessary. If the key is created correctly, two files will be created under ~ / .ssh, ʻid_rsa and ʻid_rsa.pub. Since ʻid_rsa.pub` is the public key, you will need to register its contents in Deploy Key on github. Make a copy of this public key.

cat ~/.ssh/id_rsa.pub

Register the copied public key on Github

You can register on the SSH key registration page. スクリーンショット 2020-10-24 12.42.23.png

For Title, enter a text that shows the contents of the key, and paste the public key you copied earlier into Key.

Check if you were able to register from EC2

ssh -T [email protected]

Clone the github repository from EC2 and you're done!

git clone [email protected]:yourname/yourrepo.git

スクリーンショット 2020-10-24 12.50.06.png

And docker-compose up!

Before that, I'm sorry.

sudo service docker start

And

docker-compose up

That is an error for some reason. .. .. ʻError: Cannot find module What is'express'? Isn't it properly written in package.json`? .. ..

Creating express-app ... done
Creating nginx-web   ... done
Attaching to express-app, nginx-web
express-app | node:internal/modules/cjs/loader:903
express-app |   throw err;
express-app |   ^
express-app | 
express-app | Error: Cannot find module 'express'
express-app | Require stack:
express-app | - /usr/src/app/index.js
express-app |     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:900:15)
express-app |     at Function.Module._load (node:internal/modules/cjs/loader:745:27)
express-app |     at Module.require (node:internal/modules/cjs/loader:972:19)
express-app |     at require (node:internal/modules/cjs/helpers:88:18)
express-app |     at Object.<anonymous> (/usr/src/app/index.js:1:17)
express-app |     at Module._compile (node:internal/modules/cjs/loader:1083:30)
express-app |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
express-app |     at Module.load (node:internal/modules/cjs/loader:948:32)
express-app |     at Function.Module._load (node:internal/modules/cjs/loader:789:14)
express-app |     at Function.executeUserEntryPoint [as runMain](node:internal/modules/run_main:72:12) {
express-app |   code: 'MODULE_NOT_FOUND',
express-app |   requireStack: [ '/usr/src/app/index.js' ]
express-app | }
nginx-web | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx-web | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx-web | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx-web | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
express-app exited with code 1
nginx-web | 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
nginx-web | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx-web | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx-web | 2020/10/24 02:42:13 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/nginx.conf:18
nginx-web | nginx: [emerg] host not found in upstream "app" in /etc/nginx/nginx.conf:18
nginx-web exited with code 1

As a result of various investigations, it seems that something difficult is happening.

Follow the advice and fix docker-compose.yml.

docker-compose.yml


     volumes:
      - './app:/usr/src/app'
      - usr/src/app/node_modules #Postscript

This was pretty good!

Recommended Posts

Summary of Docker understanding by beginners ⑤ ~ Until deploying docker container on EC2 instance ~
Summary of Docker understanding by beginners ④ ~ Until EC2 instance is started and docker is installed ~
Summary of Docker understanding by beginners ⑥ ~ Until automatic deployment of docker container to EC2 instance using CodeDeploy and CodePipeline ~
Summary of Docker understanding by beginners ② ~ docker-compose ~
Summary of Docker understanding by beginners ③ ~ Until proxying API using nginx ~
Summary of Docker understanding by beginners ① ~ docker run -p ~
Launch docker container on EC2 (personal memorandum)
I tried installing docker on an EC2 instance
Install docker-compose on a Graviton 2 instance of AWS EC2
Deploy laravel using docker on EC2 on AWS ① (Create EC2 instance)
[Docker] Build an Apache container on EC2 using dockerfile
Ruby on Rails for beginners! !! Summary of new posting functions
Get only the ID of the container specified by docker ps
[Java] Beginner's understanding of Servlet-①
Object-oriented summary by beginners (Java)
Summary of steps for developing in Docker container with VS Code
[Microsoft] Run Azure Pipelines (VSTS) Agent on Docker or Azure Container Instance
I tried deploying a Docker container on Lambda with Serverless Framework