首页 > 数据库 >[Docker] Add a SQLite Console Shortcut with the Dockerfile

[Docker] Add a SQLite Console Shortcut with the Dockerfile

时间:2023-05-04 14:23:59浏览次数:39  
标签:bin SQLite shell Console cli database Shortcut command local

With a long-running node server and a database, sometimes it's useful to ssh into the virtual machine to explore the file system, and look at the database.

In Dockerfile, add:

RUN echo '#!/bin/sh\nset -xe\nsqlite3 \$DATABASE_URL' > /usr/local/bin/database_cli && chmod +x /usr/local/bin/database_cli

This command will create a new file inside user/local/bin/database_cli. This file will contain a script that runs SQLite 3 on the database URL, and makes sure the script is executable.

 

After deploying the changes with fly deploy, you can use fly ssh console -C database_cli to jump straight into the SQLite CLI.

 

  1. RUN: This is a Docker command that runs a command in a new layer on top of the current image and commits the result. This is typically used for installing packages, configuring the environment, or other similar tasks.

  2. echo '#!/bin/sh\nset -xe\nsqlite3 \$DATABASE_URL': The echo command is used to print the given string to the standard output. In this case, the string is a shell script that consists of three lines:

    • #!/bin/sh: This is a shebang (or hashbang) line that specifies the interpreter to be used for executing the script, in this case, /bin/sh (a standard Unix shell).
    • set -xe: This line sets two options for the shell:
      • -x: This option tells the shell to print each command before it's executed, which is useful for debugging.
      • -e: This option tells the shell to exit immediately if any command exits with a non-zero status, which is useful for detecting errors early.
    • sqlite3 \$DATABASE_URL: This line runs the sqlite3 command-line tool with the $DATABASE_URL environment variable as its argument. The backslash before the $ is used to escape it, ensuring that the variable is not expanded when the echo command is executed but rather when the script is run.
  3. > /usr/local/bin/database_cli: This part of the command redirects the output of the echo command to a file named database_cli in the /usr/local/bin/ directory. This is a standard location for executable files on Unix-like systems.

  4. &&: This is a shell control operator that allows you to chain multiple commands together. The second command will only be executed if the first command succeeds (returns a zero exit status).

  5. chmod +x /usr/local/bin/database_cli: This command changes the permissions of the database_cli file to make it executable. The +x option adds the execute permission for the owner, group, and others.

标签:bin,SQLite,shell,Console,cli,database,Shortcut,command,local
From: https://www.cnblogs.com/Answer1215/p/17371084.html

相关文章

  • SQLite3数据库的介绍和使用(面向业务编程-数据库)
    SQLite3数据库的介绍和使用(面向业务编程-数据库)SQLite3介绍SQLite是一种用C语言实现的的SQL数据库它的特点有:轻量级、快速、独立、高可靠性、跨平台它广泛应用在全世界范围内的手机电脑应用的内建数据库官网地址:https://www.sqlite.org/index.htmlSQLite因为其采用文件存储......
  • Android提高第八篇之SQLite分页读取
    Android包含了常用于嵌入式系统的SQLite,免去了开发者自己移植安装的功夫。SQLite支持多数SQL92标准,很多常用的SQL命令都能在SQLite上面使用,除此之外Android还提供了一系列自定义的方法去简化对SQLite数据库的操作。不过有跨平台需求的程序就建议使用标准的SQL语句,毕竟这样容易在......
  • Android提高第九篇之GridView和SQLite实现分页表格
    上次讲的Android上的SQLite分页读取,只用文本框显示数据而已,这次就讲得更加深入些,实现并封装一个SQL分页表格控件,不仅支持分页还是以表格的形式展示数据。先来看看本文程序运行的动画:这个SQL分页表格控件主要分为“表格区”和“分页栏”这两部分,这两部分都是基于GridView实现的。......
  • SQLite vs Pandas
    AnalysisdetailsFortheanalysis,weranthesixtasks10timeseach,for5differentsamplesizes,foreachof3programs:pandas,sqlite,andmemory-sqlite(wheredatabaseisinmemoryinsteadofondisk).See below forthedefinitionsofeachtask.Ou......
  • .Net Core Console&Cache
    前言有时候想快速验证一些想法,新建一个控制台来弄,可控制台模板是轻量级的应用程序模板,不具备配置、日志、依赖注入等一些功能。缓存在网站开发中,缓存无处不在,它能够极大地提高硬件和软件的运行速度。性能优化的第一步便是使用缓存,例如频繁的从数据库中读取,需要和底层IO交互,性......
  • python 读写sqlite3 读写内存中的数据库
    Python中,可以使用标准库sqlite3来读写SQLite数据库。下面是一个示例代码,展示如何连接到SQLite数据库,创建表格,插入数据,查询数据和关闭数据库:importsqlite3#连接到数据库conn=sqlite3.connect('example.db')#创建一个表格conn.execute('''CREATETABLEIFNOTE......
  • python 读写sqlite3
    importsqlite3#连接到SQLite3数据库conn=sqlite3.connect('example.db')#创建一个表conn.execute('''CREATETABLEIFNOTEXISTSusers(idINTEGERPRIMARYKEYAUTOINCREMENT,nameTEXTNOTNULL,ageI......
  • 本地java监控远程Linux服务器-jconsole
    一、配置远程服务器需要监控的服务项目(本文以ps为例)需要监控的ps项目,此项目启动文件为ps.sh,编辑sh文件,找到JAVA_OPTS项,在后面添加JAVA_OPTS="-XX:+UseParallelGC-XX:+UseParallelOldGC$JVM_FLAGS$GC_LOG-Dfile.encoding=UTF-8-DLog4jContextSelector=org.apache.logging.......
  • console.log(([][[]] + [])[+!![]]+([]+{})[+!![]+ + !![]])输出什么
    简介原文链接:https://culturesun.site/index.php/archives/507.html#cl-2这是前几天阅读公众号文章遇到的一篇文章,灰常有意思,记录一下。JavaScript不愧是弱类型语言,换成其他语言,这肯定报错吧。详解直接上图:nb吧。先把这个字符串分割,依次计算值。先计算前面这个小括号---......
  • SQLite Reset Primary Key Field
    SQLiteResetPrimaryKeyField回答1Trythis:deletefromyour_table;deletefromsqlite_sequencewherename='your_table';SQLiteAutoincrementSQLitekeepstrackofthelargestROWIDthatatablehaseverheldusingthespecialSQLITE_SEQ......