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.
First we are getting a copy of
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
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)
docker exec nginxproxy nginx -t
Now, to see the changes we are going to reload the nginx inside the nginx container.
docker exec nginxproxy nginx -s reload
First we need to setup the ec2 instance by installing docker and docker-compose. Click here
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.
scp -i "docker.pem" /Users/janudabethmin/Desktop/nginx-container-in-aws/docker-compose.yml [email protected]:/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.