{"id":988,"date":"2017-02-01T06:52:55","date_gmt":"2017-02-01T09:52:55","guid":{"rendered":"https:\/\/www.semeru.com.br\/blog\/?p=988"},"modified":"2022-12-21T14:11:34","modified_gmt":"2022-12-21T17:11:34","slug":"guia-rapido-de-docker-para-desenvolvedores-spring","status":"publish","type":"post","link":"https:\/\/www.semeru.com.br\/blog\/guia-rapido-de-docker-para-desenvolvedores-spring\/","title":{"rendered":"Guia R\u00e1pido de Docker para Desenvolvedores Spring"},"content":{"rendered":"<p>\nFala pessoal recentemente eu tirei um tempo pra estudar Docker e usar deploiando aplica\u00e7\u00f5es com Spring Boot. Este \u00e9 minha lista de comandos b\u00e1sicos. Se voc\u00ea tiver alguma dica adicional que n\u00e3o est\u00e1 listada aqui sinta-se livre para mencionar nos coment\u00e1rios e eu irei atualizar o post. Lembrando que a maioria dos comandos podem ser usados em qualquer tipo de aplica\u00e7\u00e3o e n\u00e3o apenas com Spring Boot.<br \/>\n<br \/>\n<strong>Exibir informa\u00e7\u00f5es do Docker<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker info\r\n<\/pre>\n<p><strong>Listar Todas as Docker Images<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker images -a\r\n<\/pre>\n<p><strong>Listar Todos os Docker Containers que est\u00e3o em execu\u00e7\u00e3o<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker ps\r\n<\/pre>\n<p><strong>Listar Todos os Docker Containers<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker ps -a\r\n<\/pre>\n<p><strong>Iniciar um Docker Container<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker start &lt;container name&gt;\r\n<\/pre>\n<p><strong>Parar um Docker Container <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker stop &lt;container name&gt;\r\n<\/pre>\n<p><strong>Reiniciar um Docker Container <\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker restart &lt;container name&gt;\r\n<\/pre>\n<p><strong>Visualizar os logs de um Docker Container em execu\u00e7\u00e3o<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker logs &lt;container name&gt;\r\n<\/pre>\n<p><strong>Deletar um Docker Container<\/strong><\/p>\n<p>Use a op\u00e7\u00e3o -f caso precise for\u00e7ar a remo\u00e7\u00e3o.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker rm &lt;container name&gt;\r\n<\/pre>\n<p><strong>Deletar Todos os Docker Containers<\/strong><\/p>\n<p>Use a op\u00e7\u00e3o -f caso precise for\u00e7ar a remo\u00e7\u00e3o.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker rm $(docker ps -a -q)\r\n<\/pre>\n<p><strong>Remover uma Docker Image<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker rmi &lt;image name&gt;\r\n<\/pre>\n<p><strong>Remover Todas as Docker Images<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker rmi $(docker images -q)\r\n<\/pre>\n<p><strong>Acessando o Shell de um Docker Container em execu\u00e7\u00e3o<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo docker exec -it &lt;container name&gt; bash\r\n<\/pre>\n<p><strong>Saindo do Shell de um Docker Container em execu\u00e7\u00e3o<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nCTRL+P+Q\r\n<\/pre>\n<p><strong>Baixando uma imagem do DockerHub<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker pull &lt;image name&gt;\r\n<\/pre>\n<p><strong>Criando uma Tag de Uma imagem a ser commitada no DockerHub<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker tag &lt;docker hub user&gt;\/&lt;image name&gt; &lt;docker hub user&gt;\/&lt;image name&gt; \r\n<\/pre>\n<p><strong>Autenticar no DockerHub<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker login\r\n<\/pre>\n<p><strong>Enviar uma imagem para o DockerHub<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker push &lt;docker hub user&gt;\/&lt;image name&gt;\r\n<\/pre>\n<p><strong>Cosntruindo uma imagem a partir de um Dockerfile no diret\u00f3rio atual<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker build -t=&quot;&lt;image name&gt;&quot; .\r\n<\/pre>\n<p><strong>Exibir o hist\u00f3rico de um container em execu\u00e7\u00e3o<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker history &lt;container name&gt;\r\n<\/pre>\n<p><strong>Criando um Alias para um comando Docker<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nalias dps=&quot;docker ps&quot;\r\n<\/pre>\n<p><strong>Limpando o console<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nreset\r\n<\/pre>\n<p><strong>Dicas espertas de Dockerfile para developers Spring Boot<\/strong><\/p>\n<p><strong>Add Oracle Java to an Image<\/strong><\/p>\n<p>Para Ubuntu vers\u00e3o 16.10 LTS<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nFROM dockerfile\/ubuntu\r\n\r\n# Instala o Java 8.\r\nRUN \\\r\n  echo oracle-java8-installer shared\/accepted-oracle-license-v1-1 select true | debconf-set-selections &amp;&amp; \\\r\n  add-apt-repository -y ppa:webupd8team\/java &amp;&amp; \\\r\n  apt-get update &amp;&amp; \\\r\n  apt-get install -y oracle-java8-installer &amp;&amp; \\\r\n  rm -rf \/var\/lib\/apt\/lists\/* &amp;&amp; \\\r\n  rm -rf \/var\/cache\/oracle-jdk8-installer\r\n\r\n\r\n# Define o diret\u00f3rio de trabalho.\r\nWORKDIR \/data\r\n\r\n# Define a vari\u00e1vel de ambiente JAVA_HOME\r\nENV JAVA_HOME \/usr\/lib\/jvm\/java-8-oracle\r\n\r\n# Define o comando padr\u00e3o.\r\nCMD [&quot;bash&quot;]\r\n<\/pre>\n<p><strong>Adicionando e executando um .jar de uma aplica\u00e7\u00e3o Spring Boot a uma Docker Image<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nVOLUME \/tmp\r\nADD \/maven\/myapp-0.0.1-SNAPSHOT.jar myapp.jar\r\nRUN sh -c 'touch \/myapp.jar'\r\nENTRYPOINT [&quot;java&quot;,&quot;-Djava.security.egd=file:\/dev\/.\/urandom&quot;,&quot;-jar&quot;,&quot;\/myapp.jar&quot;]\r\n<\/pre>\n<h2>Treinamentos relacionados com este post<\/h2>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_docker\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Docker do 0 \u00e0 Maestria: Cont\u00eaineres Desmistificados mais 3 B\u00d4NUS\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/09-docker.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_docker_para_aws\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Docker para Amazon AWS Implante Apps Java e .NET com Travis CI\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/10-docker-to-aws.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_rest_spring_java\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"REST API's RESTFul do 0 \u00e0  AWS com Spring Boot 3, Java e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/07-rest-spring-java.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_rest_asp_net\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"REST API's RESTFul do 0 \u00e0 Azure com ASP.NET Core 5 e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/01-rest-asp.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_rest_spring_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"REST API's RESTFul do 0 \u00e0 AWS com Spring Boot 3, Kotlin e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/18-rest-spring-kotlin.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_microservices_java\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Microservices do 0 com Spring Cloud, Spring Boot e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/14-microservices-java.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_microservices-dotnet\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Arquitetura de Microsservi\u00e7os do 0 com ASP.NET, .NET 6 e C#\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/15-microservices-dotnet.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_ms_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Microsservi\u00e7os do 0 com Spring Cloud, Kotlin e Docker\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/22-ms-kotlin.png\" \/><br \/>\n    <\/a>\n<\/p>\n<p>\n    <a href=\"https:\/\/pub.erudio.com.br\/kr\/blog_kotlin\" target=\"_blank\" rel=\"noopener\"><br \/>\n        <img decoding=\"async\" style=\"max-width: 100%;\" title=\"Kotlin para DEVs Java: Aprenda a Linguagem Padr\u00e3o do Android\" src=\"https:\/\/raw.githubusercontent.com\/leandrocgsi\/blog-images\/main\/20-kotlin.png\" \/><br \/>\n    <\/a><\/p>\n<div align=\"right\"><div class=\"sharexyWidgetNoindexUniqueClassName\"><div id=\"shr_63807498\"><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Fala pessoal recentemente eu tirei um tempo pra estudar Docker e usar deploiando aplica\u00e7\u00f5es com Spring Boot. Este \u00e9 minha lista de comandos b\u00e1sicos. Se voc\u00ea tiver alguma dica adicional que n\u00e3o est\u00e1 listada aqui sinta-se livre para mencionar nos coment\u00e1rios e eu irei atualizar o post. Lembrando que a maioria dos comandos podem ser [&#8230;]<\/p>\n<div align=\"right\">\n<div class=\"sharexyWidgetNoindexUniqueClassName\">\n<div id=\"shr_63807498\"><\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[239,63,208],"tags":[240,161,210],"_links":{"self":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/988"}],"collection":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":18,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/posts\/988\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.semeru.com.br\/blog\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}