Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Let's run a MySQL instance on our local machine using docker. You don't need to install any version of mysql on your system. You won't get into trouble of upgrading the mysql or even in the trouble of removing it.

When you stop the container Mysql will be stopped. If you remove the image it will be gone forever :)

To run an instance of mySQL on your system (server or desktop), just use the below command:
docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest

NOTE: we assume that docker is installed on your system.

-p 3306:3306 will bind the container port into a port in host machine. We run it on 3306, if you have to change it you need to change the first port number to a port in your host like 3350:3306.

--name gives a name to you container, so you can easily work with the name provided.

-e will set an environment variable. Here we have set a password for our mysql root user.

-d makes the container to be run in DAEMON mode (in background).

mysql:latest this is the image name that you will pull from docker hub registry.

Voila! You are up & running we a totally working mysql server.

Let's check with netstat (on your HOST) whether it's up or not:
root@infra:~# netstat -nltp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 11572/docker-proxy

#docker #mysql #netstat #image #container
View open ports without netstat or other tool:
# Get all open ports in hex format
declare -a open_ports=($(cat /proc/net/tcp | grep -v "local_address" | awk '{ print $2 }' | cut -d':' -f2))
# Show all open ports and decode hex to dec
for port in ${open_ports[*]}; do echo $((0x${port})); done


#linux #ports #netstat #tcp #open_ports #sysadmin