How to check Docker container logs. Look for the container ID.
$ docker ps -a 3e2c1193915f |
To view the logs for the container.
docker logs 3e2c1193915f
# or
docker container logs 3e2c1193915f |
cloud engineer
by Ulysses
How to check Docker container logs. Look for the container ID.
$ docker ps -a 3e2c1193915f |
$ docker ps -a 3e2c1193915f
To view the logs for the container.
docker logs 3e2c1193915f
# or
docker container logs 3e2c1193915f |
docker logs 3e2c1193915f # or docker container logs 3e2c1193915f
by Ulysses
Here’s how to run Rocky Linux in a Docker container.
Download the image.
docker pull rockylinux/rockylinux |
docker pull rockylinux/rockylinux
Create a Rocky Linux container called bullwinkle.
docker run -it --name bullwinkle -d rockylinux/rockylinux |
docker run -it --name bullwinkle -d rockylinux/rockylinux
Login to the container using bash.
docker exec -it --user root bullwinkle /bin/bash |
docker exec -it --user root bullwinkle /bin/bash
When done, stop and delete the container.
docker ps -a docker stop container_ID docker rm container_ID |
docker ps -a docker stop container_ID docker rm container_ID
by Ulysses
Run Terraform in a Docker container.
docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest |
docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest
Create an alias.
alias terraform='docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest' |
alias terraform='docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest'
Run the command
terraform --version
Terraform v1.0.2
on linux_amd64 |
terraform --version Terraform v1.0.2 on linux_amd64
by Ulysses
You can run a gcloud commands in a Docker container.
docker run -ti --name gcloud-config google/cloud-sdk gcloud auth login |
docker run -ti --name gcloud-config google/cloud-sdk gcloud auth login
Create an alias.
alias gcloud='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gcloud' |
alias gcloud='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gcloud'
Run the command.
gcloud --version Google Cloud SDK 348.0.0 alpha 2021.07.09 app-engine-go 1.9.71 app-engine-java 1.9.90 app-engine-python 1.9.93 app-engine-python-extras 1.9.93 beta 2021.07.09 bigtable bq 2.0.70 cbt 0.10.0 cloud-datastore-emulator 2.1.0 cloud-firestore-emulator 1.13.0 cloud-spanner-emulator 1.2.0 core 2021.07.09 datalab 20190610 gsutil 4.65 kpt 0.39.3 local-extract 1.2.0 pubsub-emulator 0.4.1 |
gcloud --version Google Cloud SDK 348.0.0 alpha 2021.07.09 app-engine-go 1.9.71 app-engine-java 1.9.90 app-engine-python 1.9.93 app-engine-python-extras 1.9.93 beta 2021.07.09 bigtable bq 2.0.70 cbt 0.10.0 cloud-datastore-emulator 2.1.0 cloud-firestore-emulator 1.13.0 cloud-spanner-emulator 1.2.0 core 2021.07.09 datalab 20190610 gsutil 4.65 kpt 0.39.3 local-extract 1.2.0 pubsub-emulator 0.4.1
Create one for gsutil.
alias gsutil='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gsutil' |
alias gsutil='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gsutil'
by Ulysses
This will download the latest awscli and run it in a container.
A new container will be built every time the command is run.
Your current credentials in ~/.aws will be used.
docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli:latest |
docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli:latest
Create an alias for convenience.
alias aws='docker run --rm -ti -v ~/.aws:/root/.aws -v $(pwd):/aws amazon/aws-cli' |
alias aws='docker run --rm -ti -v ~/.aws:/root/.aws -v $(pwd):/aws amazon/aws-cli'
You can now run any aws cli after.
aws --version aws-cli/2.2.20 Python/3.8.8 Linux/5.4.0-66-generic docker/x86_64.amzn.2 prompt/off |
aws --version aws-cli/2.2.20 Python/3.8.8 Linux/5.4.0-66-generic docker/x86_64.amzn.2 prompt/off
by Ulysses
If you want to SSH to a Docker container, use the Docker exec command.
docker exec -it container_name bash |
docker exec -it container_name bash
I’m using a Git Bash terminal, so I have to prefix the docker command with winpty.
winpty docker exec -it container_name bash |
winpty docker exec -it container_name bash
Result
root@681bbe3f65f1:/var/www/html# |
root@681bbe3f65f1:/var/www/html#
Ctrl-D to exit.
by Ulysses
Here’s how to run your web application on Google Kubernetes Engine.
Create a Dockerfile. Place your web pages in the public-html directory.
FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/ |
FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/
Build a container image for Google Container Registry (GCR).
# set your project export PROJECT_ID=[project_id] # build a container image docker build -t gcr.io/${PROJECT_ID}/your-app:v1 . # verify docker images docker images |
# set your project export PROJECT_ID=[project_id] # build a container image docker build -t gcr.io/${PROJECT_ID}/your-app:v1 . # verify docker images docker images
Upload the container image to GCR.
# authenticate gcloud auth configure-docker # upload image docker push gcr.io/${PROJECT_ID}/your-app:v1 |
# authenticate gcloud auth configure-docker # upload image docker push gcr.io/${PROJECT_ID}/your-app:v1
Create a container GKE cluster.
# create cluster gcloud container clusters create your-app-cluster \ --num-nodes=2 # check clusters gcloud compute instances list |
# create cluster gcloud container clusters create your-app-cluster \ --num-nodes=2 # check clusters gcloud compute instances list
Deploy your web application.
# create deployment kubectl create deployment your-app \ --image=gcr.io/${PROJECT_ID}/your-app:v1 # see the pods kubectl get pods |
# create deployment kubectl create deployment your-app \ --image=gcr.io/${PROJECT_ID}/your-app:v1 # see the pods kubectl get pods
Expose your application to the Internet.
# expose your application kubectl expose deployment your-app \ --type=LoadBalancer \ --port 80 \ --target-port 80 # get the external ip address kubectl get service |
# expose your application kubectl expose deployment your-app \ --type=LoadBalancer \ --port 80 \ --target-port 80 # get the external ip address kubectl get service
Scale your application.
# scale to 3 replicas kubectl scale deployment your-app --replicas=3 # display the replicas kubectl get deployment your-app |
# scale to 3 replicas kubectl scale deployment your-app --replicas=3 # display the replicas kubectl get deployment your-app
Cleanup.
kubectl delete service your-app gcloud container clusters delete your-app-cluster |
kubectl delete service your-app gcloud container clusters delete your-app-cluster
by Ulysses
Run Icecast2 on a Docker container.
docker run -d \ -p 8000:8000 \ -e ICECAST_SOURCE_PASSWORD=aaaa \ -e ICECAST_ADMIN_PASSWORD=bbbb \ -e ICECAST_PASSWORD=cccc \ -e ICECAST_RELAY_PASSWORD=dddd \ moul/icecast |
docker run -d \ -p 8000:8000 \ -e ICECAST_SOURCE_PASSWORD=aaaa \ -e ICECAST_ADMIN_PASSWORD=bbbb \ -e ICECAST_PASSWORD=cccc \ -e ICECAST_RELAY_PASSWORD=dddd \ moul/icecast
Access localhost:8000 on browser. Github.