title: Deploy and run Docker in AWS
body: <p>I just finish my React and NodeJS project and create a Dockerfile for each one and then create a docker-compose file to create the docker image for each one (frontend and backend).</p>
  
  <p>I also push my images to my repository in Docker hub.
  What should I do now? I want to run my docker project in AWS EC2, so I create in my AWS dashboard a new EC2 instance and install docker there and also manage to download my images from my docker hub...</p>
  
  <p>But now I'm pretty stuck, do I need to create a container to run both of them? Do I need to run each one alone?</p>
  
  <p>Also, I'm using Nginx to use port 80 instead of the default 3000.</p>
  
  <p>I really lost now (first time working with Docker and AWS)
  Thanks!</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>My dockerfile for React is:</p>
  
  <pre><code># build environment
  FROM node:13.12.0-alpine as build
  WORKDIR /app
  ENV PATH /app/node_modules/.bin:$PATH
  COPY package.json ./
  COPY package-lock.json ./
  RUN npm ci --silent
  RUN npm install react-scripts@3.4.1 -g --silent
  COPY . ./
  RUN npm run build
  
  # production environment
  FROM nginx:stable-alpine
  COPY --from=build /app/build /usr/share/nginx/html
  # new
  COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
  EXPOSE 80
  CMD ["nginx", "-g", "daemon off;"]
  </code></pre>
  
  <p>My dockerfile for Nodejs is:</p>
  
  <pre><code>FROM node:8
  
  # Create app directory
  WORKDIR /usr/src/app
  
  # Install app dependencies
  # A wildcard is used to ensure both package.json AND package-lock.json are copied
  COPY package*.json ./
  
  RUN npm install
  
  # Bundle app source
  COPY . .
  
  EXPOSE 5000
  
  CMD [ "npm", "start" ]
  </code></pre>
  
  <p>and my Nginx config file is:</p>
  
  <pre><code>server {
  
    listen 80;
  
    location / {
      root   /usr/share/nginx/html;
      index  index.html index.htm;
      try_files $uri $uri/ /index.html;
    }
  
    error_page   500 502 503 504  /50x.html;
  
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
  
  }
  </code></pre>
  
  <p>my docker-compose.yml file is:</p>
  
  <pre><code>version: "2"
  services:
    frontend:
      image: itaik/test-docker:frontend
      build: ./frontend
      ports:
        - "80:80"
      depends_on:
        - backend
    backend:
      image: itaik/test-docker:backend
      build: ./backend
      ports:
        - "5000:5000"
  </code></pre>
  
  <p>On my computer (windows) I download the Docker desktop app and I using the docker compose-up command and it's create a container with both of my images and everything is great, this is what i'm trying to achieve on my AWS EC2 (Linux).
  Hope things more clear now.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Ok so somehow I manage to run both my images with difference containers and they are now both online like I wanted 
  I use the command:</p>
  
  <p><code>docker run -d -p 5000:5000 itaik/test-docker:backend</code></p>
  
  <p><code>docker run -d -p 80:80 itaik/test-docker:frontend</code></p>
  
  <p>But now, for some reason all my API calls to "localhost:5000" are getting an error:</p>
  
  <p><code>GET http://localhost:5000/user/ net::ERR_CONNECTION_REFUSED</code></p>
  
  <p>Is this related to my React/Nodejs code or to the way I setup my docker images?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>Even after I use docker-compose and both images are running on the same network bridge I still got that error.</p>
  
  <p>The only solution I can think about is to manually edit my code and change "localhost" to AWS public IP, but I guess I just missing something that need to be done...
  Maybe my network bridge is not visible to the public IP somehow?
  Because I do get response when I enter to the public IP (port 80) and to port 5000.</p>
  
  <p>But the API call to localhost:5000 is getting an error.</p>