-
docker build -t studentapi .
-
Create a network:
docker network create studentapi-network
-
Start the SQL Server container and put it in a network:
docker run --net=studentapi-network -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password1!" -p 1433:1433 --name sqlserver -d microsoft/mssql-server-linux
-
Run the API container, put it in the same network:
docker run --net=studentapi-network --rm -p 5000:5000 -e "DatabaseServer=sqlserver" -e "DatabaseUserPassword=Password1!" studentapi
Helpful docker commands
List all containers: docker ps -a
Stop all containers: docker stop $(docker ps -aq)
Remove all containers: docker rm $(docker ps -aq)
The ECS CLI allows us to deploy multi container apps with docker-compose. Currently ECS only supports version 2 of the docker-compose syntax. More about the gotchas of docker-compose on the ECS CLI.
Linux
-
Install the ECS CLI:
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
-
Configure the ECS CLI
ecs-cli configure --region ap-southeast-2 --access-key AWS_ACCESS_KEY --secret-key AWS_SECRET_KEY --cluster studentapi-demo
-
Create an ECS cluster Here we create an ECS cluster which is 1 instance of type t2.medium, note that we need to generate a key pair in EC2 dashboard which maps to
EC2_KEY_PAIR_NAME
hereecs-cli up --keypair EC2_KEY_PAIR_NAME --capability-iam --size 1 --instance-type t2.medium --force
-
Create and start an ECS task Create an ECS task definition and run the containers (From a directory containing a
docker-compose.yml
):ecs-cli compose up
-
List running containers (Gives you the status of the container cluster and if running the public IP)
ecs-cli compose ps
Windows Install and configure the ECS CLI first. Then:
-
aws iam --region ap-southeast-2 create-role --role-name ecsExecutionRole --assume-role-policy-document file://execution-assume-role.json
-
aws iam --region ap-southeast-2 attach-role-policy --role-name ecsExecutionRole --policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
-
aws logs create-log-group --log-group-name ecsDemoLogs --region ap-southeast-2
-
ecs-cli configure profile --access-key ACCESS_KEY_ID --secret-key SECRET_ACCESS_KEY --profile-name ecsDemoProfile
-
ecs-cli configure profile default --profile-name ecsDemoProfile
-
ecs-cli configure --cluster studentapi-demo-cluster --default-launch-type EC2 --region ap-southeast-2 --config-name ecsDemoConfig
-
ecs-cli up --keypair ecs-demo --capability-iam --size 1 --instance-type t2.medium --force
-
ecs-cli compose --file docker-compose.yml up
-
ecs-cli ps
-
ecs-cli down --force
.Net Core and SQL Server In Docker - Part 1
Building and shipping a .NET Core application with Docker and TravisCI
Amazon ECS: using the CLI with Docker Compose
Docker cluster management on AWS