Last active
November 29, 2017 15:53
-
-
Save adrianolsk/e06071a8d71b818522c762cce0f1299c to your computer and use it in GitHub Desktop.
Ubuntu Server snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extract tar | |
tar -xvzf community_images.tar.gz | |
#create tar | |
tar -cvzf filename.tar.gz file.js | |
#example with exclude | |
tar -czvf out/app.tar.gz --exclude=./out --exclude=./node_modules . | |
sudo apt-get install unzip | |
unzip file.zip -d destination_folder | |
# See contents of tar without extract | |
tar -tf backup.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List docker images | |
sudo docker images | |
#list docker containers | |
sudo docker ps | |
#open bash inside a container | |
sudo docker exec -it yourContainer bash | |
Accessing the Database | |
You can't access the MongoDB from the outside the server. To access the MongoDB shell you need to log into your server via SSH first and then run the following command: | |
docker exec -it mongodb mongo <appName> | |
Later on we'll be using a separate MongoDB instance for every app. | |
#Build a Docker image using the Dockerfile: | |
docker build -t msanand/node . | |
#run | |
docker run -d --link mongodb --name your_container --restart=always your/imagename | |
#turn localhost from host available to cantainer | |
--net=host" | |
#create image from container | |
docker commit -p 07fde139a208 rss | |
docker images | |
Save image with id: | |
sudo docker save -o /home/matrix/matrix-data.tar matrix-data | |
sudo docker load -i <path to copied image file> | |
#restart docker daemon | |
sudo /etc/init.d/docker restart | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run -d --name web nginx:alpine | |
Then update the restart-policy; | |
docker update --restart=always web | |
docker run -d --name [container] --restart=always -p 8081:8080 [imagename] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo apt-get install apache2-utils | |
#sudo htpasswd -c /etc/nginx/.htpasswd nginx | |
sudo apt-get install nginx | |
sudo nano /etc/nginx/nginx.conf | |
sudo nginx -s reload | |
http{ | |
server { | |
listen 80; | |
server_name 127.0.0.2; | |
location / { | |
proxy_pass http://127.0.0.1:4000; | |
proxy_http_version 1.1; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $host; | |
proxy_set_header Upgrade $http_upgrade; | |
# proxy_set_header Connection $connection_upgrade; | |
#auth_basic "Private Property"; | |
#auth_basic_user_file /etc/nginx/.htpasswd; | |
} | |
} | |
server { | |
listen 80; | |
server_name 127.0.0.10; | |
root /home/adrianolsk/Documents/; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo service ssh reload | |
sudo service ssh restart | |
#Create a ssh tunnel on localhost:8080 to server:8080 and server:5000 to localhost:3000 | |
ssh root@SERVER_IP -L 8080:127.0.0.1:8080 -R 5000:127.0.0.1:3000 | |
#kill ssh lost connections | |
type "who" to see active connections ips | |
Type pgrep -c sshd which should print a number. It that number is zero, no-one is connected right now. If not, proceed: | |
Type pkill --signal HUP sshd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install wkhtmltopdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment