Docker Handbook (🚧Continuous Update)

1. Install docker and docker-compose on Ubuntu sudo apt-get update sudo apt install docker.io sudo apt install docker-compose 2. Configure rootless user to run docker sudo groupadd docker sudo usermod -aG docker $USER # Linux user can run below to activate the changes newgrp docker docker ps https://docs.docker.com/engine/install/linux-postinstall/ 3. List and delete images docker images docker iamge ls docker rmi <image_id_1> <image_id_2> 4. Check if the specific docker image exists IMAGE_ID=$(docker images | grep 'portainer/base' | awk '{ print $3 }') if [[ -n ${IMAGE_ID} ]]; then docker rm -f ${IMAGE_ID}; fi 5. Login remote registry # Default is dockerhub. username is docker hub id docker login # Login the specific registry docker login registry.private.com 6. Build image from Dockerfile docker build -t <user>/<repo>:<tag> -f Dockerfile . 7. Push the local image to remote registry docker image push <user>/<repo>:<tag> # Push to the private registry docker push registry.private.com/<repo>:<tag> 8. Add and view the docker volume # add volume docker volume create <volume_name> # view volume docker volume ls sudo ls /var/lib/docker/volumes 9. Check the volume detail docker volume inspect <volume_name> 10. Test docker container service connection with curl ping the http service ...

[Golang] Write a simple CLI program

I will show a simple example in this post. Let’s say the program called cli-example. package main import ( "flag" "fmt" "os" ) func main() { command := os.Args[1] os.Args = append(os.Args[:1], os.Args[2:]...) switch command { case "version": fmt.Println("1.1.1") } } The 1st argument will always be the binary name, so the command starts from the 2nd argument. If your app also needs the subcommand, then extract it from the 3rd argument, like docker image ls. ...

Helm Handbook (🚧Continuous Update)

Helm is the package manager for Kubernetes. We can download it from here Take the public repository portainer/k8s as an example 1. Render the helm chart locally Open the terminal under the path github.com/portainer/k8s/charts helm template portainer/ # Render the chart with configurable argument helm template portainer/ --set image.tag="2.6.0" helm template portainer/ --set enterpriseEdition.enabled=true --set enterpriseEdition.image.tag="2.7.0" 2. Install helm chart helm install --create-namespace -n portainer portainer portainer/portainer 3. Install helm chart with local repository helm install --create-namespace -n portainer portainer-local portainer/ \ --values portainer/values.yaml # with argument helm install --set image.tag="2.6.0" --create-namespace \ -n portainer portainer-2-6 portainer/ \ --values portainer/values.yaml 4. helm chart repo # Add repo helm repo add <repo_name> https://portainer.github.io/k8s/ helm repo update # Remove repo helm repo remove <repo_name> 5. Delete helm namespace helm delete -n portainer portainer 6. List helm namespace helm ls --all-namespaces

[microk8s] Troubleshooting Microk8s Installation on macOS

Error: Your Command Line Tools are too outdated By following the instruction from the official website Alternative install methods: macOS, I got an error while running brew install ubuntu/microk8s/microk8s as shown below As the prompt suggested, I installed the latest Xcode from the AppStore. (It took quite long to be honest). But it still showed the same error after updating the Xcode to the 13.2.1 The trick is that we should run the following commands: ...

[Git] How to work with remote repository (with example)

When we manage and maintain a public github repository, it is common to see a case that a fixed branch from outside contributor’s is staled. The reasons can be The github repository owner/maintainer and contributor did not actively process the issue in time. The contirbutor only commited the changes in his branch but didn’t make a pull request, and after a period, he is not reachable. Other reasons… Overall, it is not easy to maintain a public github repository, especially the one with lots of stars. This post will show a way to solve the above issue with a git feature. ...

[Git] How to ignore the commited file

In Git, we can ignore to track of a file or folder by adding their paths into the file .gitignore. However, sometimes we could mistakenly commit and push file and folders that are not needed to be tracked by Git. In such case, .gitignore will be not working. The issue can be solved by the below steps: Add the file path into .gitignore file. Remove the commited file from the git cache by git rm --cached bar/foo.log Commit the changes by git commit -m "xxx" After executing the above steps, you can see the file bar/foo.log is still there but will be not tracked by Git. ...

parse json arguments from command-line flags

[Golang] How to parse the JSON arguments from the Command-line flags

Passing the JSON argument via the Command-line flag seems to be not typical, but we may need it in some cases. This post will show you how to implement it in Golang. The package flag provides an easy way to implement it. Let’s take a look at a simple example of using package flag first: package main import ( "flag" "fmt" ) func main() { var version string // parse the value of the flag setVersion to variable version flag.StringVar(&version, "setVersion", "1.0.0", "") flag.Parse() fmt.Println("version = ", version) } The output is ...

DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !