<p>Check netstat -tlpn on the VPS, can you see 0.0.0.0:3306 or something like that? If so, check the firewall. Both the firewall in the operating system and the firewall from the VPS provider (if there is any). As a last resort (and not a bad idea) - you can connect to your VPS via VPN - there are good openvpn tutorials on the internet. The reason why the VPN is a good idea - especially for a development server is that you may need to allow the user from everywhere (if you do not have a static IP address) and if you accidentally create some 'testuser' with 'testpassword' anybody from the internet will be able to connect to your db. So use good passwords, limit access to your public IP and use VPN if possible.</p>

CC BY-SA 4.0
2021-02-06T14:02:34.447Z
2021-02-06T14:02:34.447Z
petrchpetr
<p>I created a docker container with docker-compose in my VPS and I want to access it from my local computer but the connection will refuse. also, I allowed the 3306 port in the VPS.</p>
<p>my <code>docker-compose.yml</code> file:</p>
<pre><code>version: &quot;3&quot;

services:
  mariadb:
    image: mariadb
    container_name: mariadb
    restart: 'always'
    volumes: 
      - ./conf:/etc/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${password}
      MYSQL_DATABASE: ${database}
      MYSQL_USER:  ${username}
      MYSQL_PASSWORD: ${password}
    ports:
      - 3306:3306
</code></pre>
<p>how may I access the MariaDB server from my local computer?</p>

<docker><docker-compose>
docker mariadb access from remote
Amir Sasani
# docker mariadb access from remote

(Asked by: username_0 on 2021-02-05)

I created a docker container with docker-compose in my VPS and I want to access it from my local computer but the connection will refuse. also, I allowed the 3306 port in the VPS.
my docker-compose.yml file:
version: "3"

services:
  mariadb:
    image: mariadb
    container_name: mariadb
    restart: 'always'
    volumes: 
      - ./conf:/etc/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${password}
      MYSQL_DATABASE: ${database}
      MYSQL_USER:  ${username}
      MYSQL_PASSWORD: ${password}
    ports:
      - 3306:3306

how may I access the MariaDB server from my local computer?

**Tags:** docker, docker-compose


---

## 1 answers

### Answer by username_1 on 2021-02-06. Score: 1

Check netstat -tlpn on the VPS, can you see 0.0.0.0:3306 or something like that? If so, check the firewall. Both the firewall in the operating system and the firewall from the VPS provider (if there is any). As a last resort (and not a bad idea) - you can connect to your VPS via VPN - there are good openvpn tutorials on the internet. The reason why the VPN is a good idea - especially for a development server is that you may need to allow the user from everywhere (if you do not have a static IP address) and if you accidentally create some 'testuser' with 'testpassword' anybody from the internet will be able to connect to your db. So use good passwords, limit access to your public IP and use VPN if possible.


---

