Last active
May 4, 2022 17:43
-
-
Save thuliumsystems/df8fc7ad9300af7723c68446a98f9bf6 to your computer and use it in GitHub Desktop.
Docker
This file contains 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
const http = require('http'); | |
const hostname = '0.0.0.0'; | |
const port = 3333; | |
const server = http.createServer((req, res) => { | |
res.statusCode = 200; | |
res.setHeader('Content-Type', 'text/plain'); | |
res.end('Hello World'); | |
}); | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
This file contains 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
const { Sequelize } = require('sequelize'); | |
const sequelize = new Sequelize('mariadb://root:123456@ip:3307/database') | |
sequelize | |
.authenticate() | |
.then(() => { | |
console.log('Connection has been established successfully.'); | |
}) | |
.catch(err => { | |
console.error('Unable to connect to the database:', err); | |
}); |
This file contains 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
FROM debian:latest | |
RUN apt update -y | |
RUN apt install net-tools curl -y |
This file contains 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
1. Criar a imagem do Debian que será usada pelos contâiners (executar no mesmo diretório do Dockerfile) | |
docker build -t debian . | |
2. Criar os contâiners | |
2.1 MySQL | |
docker run -d -it --expose=3306 -p 3306:3306 --name mysql debian | |
2.2 Node | |
docker run -d -it --expose=3333 -p 3333:3333 -v /caminho/arquivos_node/no_meu_pc:/usr/local --workdir="/usr/local" --name nodejs debian | |
3. Configurar os contâiners | |
3.1 MySQL | |
docker exec mysql apt update | |
docker exec mysql apt install mariadb-server mariadb-client -y | |
docker exec mysql sed -i 's/#port = 3306/port = 3306/g' /etc/mysql/mariadb.conf.d/50-server.cnf | |
docker exec mysql sed -i 's/bind-address = 127.0.0.1/bind-address = 0.0.0.0/g' /etc/mysql/mariadb.conf.d/50-server.cnf | |
docker exec mysql service mariadb start | |
docker exec mysql mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'' IDENTIFIED BY '123456' WITH GRANT OPTION;" | |
(A) docker exec mysql service mariadb restart | |
3.2 Node | |
docker exec nodejs curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh | |
docker exec nodejs bash nodesource_setup.sh | |
docker exec nodejs apt install -y nodejs | |
no diretório usado no 2.2, crie o arquivo app.js e rode o comando abaixo | |
(B) docker exec nodejs src/app.js | |
(daqui pra cima é pra tudo estar rodando de boa) | |
3.3 Para usar o nodemon | |
docker exec nodejs npm init -y | |
docker exec nodejs npm i -g nodemon | |
(C) docker exec nodejs nodemon src/app.js | |
4. Gerenciar os contâiners (caso necessário) | |
4.1 Iniciar | |
docker start mysql | |
docker start nodejs | |
4.2 Conectar | |
docker attach mysql ou nodejs | |
4.3 Desconectar | |
exit (se atente que ao fazer isso, o contâiner vai parar, então execute (A) e/ou (B) ou (C) para iniciá-los novamente) | |
4.3 Parar | |
docker stop mysql ou nodejs | |
5. Verificar contâiners | |
docker ps | |
6. Quando o pc for ligado, é preciso executar os comando (A) e (B) ou (C) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment