Locally...
touch DockerFile
touch .dockerignore
node_modules
npm-debug.log
Build the Image:
Updated command: docker image build -t nameofimage:1.0 .
docker build -t <your username>/crypto-api .
Run the Image:
docker run --env-file .env -p 8080:8080 -d andimiya/crypto-api
Get the Container ID:
docker ps
Print app output:
docker logs <container id>
Should see something like:
Running on http://localhost:8080
Look inside the container:
docker exec -it <container id> /bin/bash
NOTES:
- bash isn't installed on any alpine images
FROM node:7.10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json .
# For npm@5 or later, copy package-lock.json as well
# COPY package.json package-lock.json ./
RUN npm install
# If you are building your code for production
# RUN npm install --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
Set up security groups, open necessary ports
ssh into the EC2
ssh -i "AndreaKeyPair.pem" ec2-user@ec2-34-238-43-66.compute-1.amazonaws.com
sudo yum install vim
touch .env
vim .env
sudo yum install -y docker
- Unless EC2 is pre-loaded with Docker
Populate the .env file with environment variables, don't put export
in front of the variables!
docker pull andimiya/crypto-api
docker run --env-file .env -p 8080:8080 -d andimiya/crypto-api
curl localhost:8080 from inside the ec2
curl an endpoint from inside the ec2
- Build from local
docker build --no-cache -t andimiya/crypto-api .
- Push from local to Docker
docker push andimiya/crypto-api
- ssh into EC2 instance
ssh ec2-user@34.212.0.41 -i ~/.ssh/AndreaWestKeyPair.pem
- Stop the running docker container
- Pull down the latest docker image (
docker pull andimiya/crypto-api
) - Run
docker run --env-file .env -p 8080:8080 -d andimiya/crypto-api
- Pull down the latest docker image (
Static site hosting
Set error file to: index.html
Make a deploy.sh
file:
npm run build
aws s3 sync build/ s3://andimiya-crypto-app --delete --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers