Linux ‐ Docker And Services - erikpa1/MyExperience GitHub Wiki
TODO:
- install docker - mac
- create docker image - golang server
- install docker on ubuntu
- pull image from cmd
- install image from ZIP
- Try docker on Raspberi PI
sudo apt install docker.io
docker run -d -p 27017:27017 --name mongo mongo:8
docker update --restart unless-stopped mongo
docker start mongo
Node JS express
sudo docker run --rm -p 3000:3000 node:22-alpine node -e "require('http').createServer((req,res)=>res.end('Hello World\n')).listen(3000)"
sudo nano /etc/systemd/system/<SERVICE_NAME>.service
sudo micro /etc/systemd/system/<SERVICE_NAME>.service
[Unit]
Description=My Go application
After=network.target
[Service]
Type=simple
User=erik
WorkingDirectory=/home/erik/myapp
ExecStart=/home/erik/myapp/main
Restart=on-failure
RestartSec=5
# Environment variables — option A: inline
Environment="PORT=8080"
Environment="MONGO_URI=mongodb://localhost:27017"
# Option B: load from a file
EnvironmentFile=/home/erik/myapp/.env
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now <SERVICE_NAME>
systemctl status <SERVICE_NAME>
journalctl -u <SERVICE_NAME> -f # follow logs (stdout/stderr go here)
sudo systemctl daemon-reload
sudo systemctl restart <SERVICE_NAME>
journalctl -u <APPNAME> -n 200 --no-pager # last 200 lines
systemctl show myservice -p Environment
systemctl show myservice -p EnvironmentFiles
# or see the full unit definition:
systemctl cat myservice
echo "$MY_VAR"
printenv MY_VAR
sudo apt get unzip
unzip "<FILE>.zip"
- Check executable type
file ./yourfile
- if error sudo: ./goproxy: command not found or permission denied
chmod +x ./<EXE_NAME>
sudo ./<EXE_NAME>
#This is for running 443
sudo setcap 'cap_net_bind_service=+ep' /path/to/your-binary
- Unzip permission
When you copy executable with ssh you have to add it separate permissions. But when unziping executable executable receives permissions of user.