[AWS] Lab: Docker and CodeCommit Part 1
Overview
Create IAM User with CodeCommit Access
Configure local AWS user
aws configure
HTTPS Git credentials for AWS CodeCommit
Create CodeCommit Repo
- Clone the Repo by using HTTPS
- Copy Dockerfile and buildspec.yml to your local repo
Dockerfile
FROM ubuntu:12.04 # Install dependencies RUN apt-get update -y RUN apt-get install -y apache2 # Install apache and write hello world message RUN echo "Helloo Cloud Gurus!!!! This web page is running in a Docker container!" > /var/www/index.html # Configure apache RUN a2enmod rewrite RUN chown -R www-data:www-data /var/www ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
buildspec.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | version: 0.2 #env: #variables: # key: "value" # key: "value" #parameter-store: # key: "value" # key: "value" phases: install: commands: - nohup /usr/local/bin/dockerd --host=unix: ///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2& - timeout 15 sh -c "until docker info; do echo .; sleep 1; done" pre_build: commands: - echo Logging in to Amazon ECR.... - aws --version # update the following line with your own region - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin xxxx.dkr.ecr.us-east-1.amazonaws.com build: commands: - echo Build started on `date` - echo Building the Dockeroo image... # update the following line with the name of your own ECR repository - docker build -t mydockerrepo . # update the following line with the URI of your own ECR repository (view the Push Commands in the console) - docker tag mydockerrepo:latest xxxx.dkr.ecr.us-east-1.amazonaws.com/mydockerrepo:latest post_build: commands: - echo Build completed on `date` - echo pushing to repo # update the following line with the URI of your own ECR repository - docker push xxxx.dkr.ecr.us-east-1.amazonaws.com/mydockerrepo:latest #artifacts: # - location # - location #discard-paths: yes #base-directory: location #cache: #paths: # - paths |
- Push files to remote CodeCommit repo
Next, we are going to create a Elastic Container Service to able to run our Docker image.
Create ECS
Once it successed, you should be able to see your cluster:
Create Repositories
- Give a name for your repo, for example: `mydockerrepo`
- Click button "View Push Commands"
When you run the first command, you will get Auth Error, what you need to is add permission to your created user
Add Permisson for User
- Run the "View Push Commands" again, you will see "Login Successed"
- Build Docker image
- Tag Docker image
- Push Docker image
- Click "Copy URI" in last image, we need to use it later
Launch Docker Container
- Go to Task Definitions
- Give a name `mytaskdef`
- Click "Add Container"
- "image" is the URI that we just copy
- Create a Service
- Launch Type should be "EC2"
- Service name: "myservice"
- Number of tasks: 1
- Rest should be default
You should see service has reached a stead state
- Go back to "Cluster" -> "myCluster" -> "EC2 instance" -> Copy "IPV4 public address" -> Open in Broswer
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-04-07 [Algorithm] Longest Substring Without Repeating Characters?
2016-04-07 [Angular 2] Using Promise to Http
2016-04-07 [Angular 2] *ngFor with index