ALPINE COMMANDS

Description of your first forum.
Post Reply
admin
Site Admin
Posts: 22
Joined: Sat Jun 20, 2020 1:29 pm

ALPINE COMMANDS

Post by admin »

In previous topics i already discussed about Alpine Linux. Still a brief about alpine linux is smallest linux with full docker support.
Listing here few usefull commands for Alpine Linux.

1. Assign Static Ip Address:

Code: Select all

auto eth0
iface eth0 inet static
        address 192.168.0.25
        subnet 255.255.255.0
        gateway 192.168.0.1
2. If you have installed Alpine in virtual machine sometime harddisk size needs to be incresed. Accordingly partition table needs to be modified.

Code: Select all

# after the virtual disk has already been expanded.
   apk add --no-cache cfdisk e2fsprogs-extra
# choose partition then "Resize" > "Write" (to finalize)
   cfdisk
# replace * with partition you are resizing
   resize2fs /dev/*
3. In virtuslbox disk size increases when application is installed or copied, but it remain extended evenif uninstalled/delete. To shrink the space one has to fill zero at free space. In Ubuntu a popular tool is used called zerofree. Though zerofree can be installed in Alpine, but as the disk is already mounted you cannot apply zero free. There is a way to zero fill free spaces in Alpine Linux.The code is:

Code: Select all

$ cat /dev/zero > zero.file
cat: write error: No space left on device
$ sync
$ rm zero.file 
$ sync
After this we need to shrink the vbox hard disk from command prompt. Code is:

Code: Select all

vboxmanage modifymedium --compact /path/to/thedisk.vdi
4. Sometime it is required to copy data from host machine to virtual machine running Alpine. A folder to be attached in virtualbox. Inside Alpine code is:

Code: Select all

mkdir -p /mnt/shared
apk add virtualbox-guest-additions linux-virt
reboot
Then mount the above folder

Code: Select all

modprobe -a vboxsf 
mount -t vboxsf  vbox_shared /mnt/shared
vbox_shared is the 'Folder Name' you decided in the virtualbox gui

5. Sometime host machine dont have internet. To install docker one can pull in a machine with internet and export this image with docker save command. Then compress it and load it with host having no internet with docker load command. The code is:
In machine with internet:

Code: Select all

apk add gzip
docker pull couchbase
docker save couchbase > couchbase.tar
ls -lh couchbase.tar
gzip -9 couchbase.tar
ls -lh couchbase.tar.gz
In host machine without internet:

Code: Select all

docker load < couchbase.tar.gz
6. Sometime jupyter notebook is made to run inside docker with port: 8888 forwarded. Still when notebook is started it shows on localhost. In order to access it from outside, you need to bind it with 0.0.0.0. The code is:

Code: Select all

jupyter-notebook --allow-root --ip 0.0.0.0 --port 8888
7. Docker create interactive container with port forward:

Code: Select all

docker create -t -i   -p:3000:3000 --name myubuntu ubuntu:latest
8. Docker start:

Code: Select all

docker start myubuntu
9. Docker access bash:

Code: Select all

docker exec -it myubuntu /bin/bash
10. See all open ports:

Code: Select all

netstat -lnptu
11. See a application loaction:

Code: Select all

which <application_name>

Post Reply