You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Docker whale will appear on status bar and click to login with your username password
2. 🐳Create Dockerfile
cd inside your Go Project that has RESTful API
$ cd myproject && touch Dockerfile
// Paste the following snippets into Dockerfile
# Golang Dockerfile
FROM golang
ADD . /go/src/github.com/username/projectname
WORKDIR /go/src/github.com/username/projectname
RUN go get ./
RUN go build
ENTRYPOINT /go/bin/projectname
EXPOSE 8080
-d means run this detached, as a daemon, eg, not dependent on the terminal session
-p means map ports; mapping :
4. 🐳Create Docker tag to be pushed in Docker's Hub Repository
* docker tag <image ID><docker hub username>/<image name>:<version label or tag>
🐳
$ docker tag projectname username/projectname
$ docker login
$ docker push username/projectname
$ docker run -d -p 80:8080 username/projectname
// Run again at http://localhost:8080 but with docker being pulled from Docker Hub
🐳
Click Launch Instances and select "Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type" meant for Docker
t2.micro (Free tier eligible) is sufficient for starting up, press (Next: Configure Instance Details)
Press (Next: Add Storage) & (Next: Add Tags)
Press (Add another tag), insert "name" @ key & insert "ssh-and-http-from-anywhere" or projectname @ value, then Press (Next: Configure Security Group)
Press (Add Rule), pick HTTP from dropdown
Press (Review and Launch)
Press Launch
Select "Create a new key pair" & fill "Key pair name" with your projectname
Download Key Pair and store in secure place
Press (Launch Instances) and wait for it to set-up
6. 🐳Getting Connected with AWS
// Your key must not be publicly viewable for SSH to work
$ chmod 400 ~/.ssh/projectname.pem
// Press Connect on your AWS instance using its Public DNS after "ec2-ucer@""$ ssh -i ~/.ssh/projectname.pem ec2-user@<public-DNS>
// Put 'yes'if the text below appear
The authenticity of host 'ec2-xx-xxx-x-xxx.us-west-1.compute.amazonaws.com (xx.xxx.x.xxx)' can't be established.ECDSA key fingerprint is SHA256:GRwSxxxxxxxxxxJ2BMT/vVxxxxxE.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'ec2-xx-xxx-x-xxx.us-west-1.compute.amazonaws.com (xx.xxx.x.xxx)' (ECDSA) to the list of known hosts. __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___|https://aws.amazon.com/amazon-linux-ami/2018.03-release-notes/10 package(s) needed for security, out of 11 availableRun "sudo yum update" to apply all updates.
7. 🐳Environment set-up on your AWS machine
// Update & install docker
[ec2-user@ip-xxx-xx-x-xx ~]$ sudo yum update -y
[ec2-user@ip-xxx-xx-x-xx ~]$ sudo yum install -y docker
[ec2-user@ip-xxx-xx-x-xx ~]$ sudo service docker start
[ec2-user@ip-xxx-xx-x-xx ~]$ sudo usermod -a -G docker ec2-user
// Logout and log back in
🐳
[ec2-user@ip-xxx-xx-x-xx ~] exit
[ec2-user@ip-xxx-xx-x-xx ~]$ docker info
[ec2-user@ip-xxx-xx-x-xx ~]$ docker run -d -p 80:8080 username/projectname
[ec2-user@ip-xxx-xx-x-xx ~]$ docker images
[ec2-user@ip-xxx-xx-x-xx ~]$ docker ps
🐳
8. 🐳f you can see your projectname after running docker ps, then you can NOW visit your Public DNS (IPv4) from AWS instance
🐳Miscellaneous Docker's commands
// Check the docker version
$ docker version
// See all running containers on your machine
$ docker ps
// See all docker images on your machine
$ docker images
// Remove Docker-Whale images
$ docker rmi -f <image ID or image name>