An open API service indexing awesome lists of open source software.

https://github.com/itzzjb/nginx-docker-container-in-aws

Running Nginx container and a Nodejs container in AWS ec2 instance
https://github.com/itzzjb/nginx-docker-container-in-aws

aws docker ec2-instances nginx

Last synced: about 2 months ago
JSON representation

Running Nginx container and a Nodejs container in AWS ec2 instance

Awesome Lists containing this project

README

          

> [!NOTE]
> Remember to link (with a link or a network) both nginx container and nodejs container in order them to work. If you are using a docker-compose file of version 3 the links will be automatically created by the bridge network.

# Creating a new image out of a container without a Dockerfile

### Copying files between file nginx container and Desktop (Docker host)

First we are getting a copy of

```sh
docker cp nginxproxy:/etc/nginx/conf.d/default.conf ~/Desktop/default.conf
```

After doing the required changes we can can save the local file, and then replace the file inside the container with it

```sh
docker cp ~/Desktop/default.conf nginxproxy:/etc/nginx/conf.d/
```

We can validate and test nginx after the changes. (Testing to check whether the nginx command works inside the container)

```sh
docker exec nginxproxy nginx -t
```

Now, to see the changes we are going to reload the nginx inside the nginx container.

```sh
docker exec nginxproxy nginx -s reload
```

## Copying the docker-compose file into the AWS ec2 instance

First we need to setup the ec2 instance by installing docker and docker-compose.
[ Click here](https://tejaksha-k.medium.com/how-to-install-docker-and-docker-compose-to-ubuntu-20-04-azure-vm-and-aws-ec2-instances-72a498755c15)

Open the terminal from the folder where the pem file is, and copy the local file to the ec2 instance using a command similar to the below command.

```sh
scp -i "docker.pem" /Users/janudabethmin/Desktop/nginx-container-in-aws/docker-compose.yml ubuntu@ec2-3-82-220-118.compute-1.amazonaws.com:/home/ubuntu/
```

Now we can use this file to run the container by pulling the images from docker hub registry.

> [!CAUTION]
> But because I have a M1 Mac, and the images built on my M1 Mac will not work on an AWS instance. I will have to build the images on the AWS instance in order to those images to support in a AWS ec2 instance. So, either I would need to upload all the files to the AWS instance using scp or clone a git repository from the AWS instance and run the docker compose file while building the images locally using the Dockerfiles.